我正在查看模块中的这一行:
window[this.options.layer].push(to.gtm || { event: this.options.pageViewEventName, pageType: 'PageView', pageUrl: to.fullPath, routeName: to.name })
任何想法都应如何提供在上一行中传递的to.gtm
值?我尝试挂钩到组件中的beforeRouteEnter
,但是即使更改to.gtm
属性,传递给to.params
的值似乎也无法通过。
beforeRouteEnter(to, from, next) {
if (process.client) {
console.log('BRE', to, window.dataLayer);
if (to.params.test123) {
next();
} else {
const newTo = Object.assign({}, to);
newTo.gtm = { event: 'nuxtRoute3' };
newTo.params.test123 = 'test';
console.log(newTo);
next(newTo);
}
} else {
next();
}
}