Is there a way to reload the AdSense banner ads when the router changes? I've been encountering issues trying to re-add the script and HTML properly. Any guidance on how this should be done would be greatly appreciated...
This is just a test for one of the proposed solutions.
Edit:
<div v-if="ads" class="ads"><ins v-if="adsense" :key="id" class="adsbygoogle" style="display: inline-block; width: 320px; height: 50px;" data-ad-client="ca-pub-XXX" data-ad-slot="XXX"></ins></div>
...
data () {
return {
device: {},
ads: false,
adsense: false,
id: 1
}
}
...
methods: {
AdSense: function () {
(window.adsbygoogle = window.adsbygoogle || []).push({})
}
}
...
mounted: async function () {
let adsense = document.createElement('script')
adsense.setAttribute('data-ad-client', 'ca-pub-XXX')
adsense.setAttribute('async', '')
adsense.setAttribute('src', 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js')
document.head.appendChild(adsense)
this.ads = true
this.adsense = true
this.AdSense()
}
...
watch: {
$route (to, from) {
if (to !== from && to.name !== 'authorize' && this.device.platform === 'web') {
this.id++
}
}
}