Timing issue with vue-meta
See original GitHub issuepageviewTemplate is resolved before vue-meta has synced the page components head.
Reproduce:
- Download Nuxt.js starter template
- Install analytics module and set pageviewTemplate:
// nuxt.config.js
'google-analytics': {
id: 'UA-XXXXXX',
debug: {
enabled: true,
},
autoTracking: {
pageviewTemplate: route => {
return {
page: route.path,
title: document.title,
location: window.location.href,
};
},
},
},
- Setup two pages:
<!-- pages/page1.vue -->
<template>
<div>
<h1 class="title">Page 1</h1>
<div class="links">
<nuxt-link to="page1">Page 1</nuxt-link>
<nuxt-link to="page2">Page 2</nuxt-link>
</div>
</div>
</template>
<script>
export default {
head() {
return {
title: 'Page 1',
};
},
}
</script>
<!-- pages/page2.vue -->
<template>
<div>
<h1 class="title">Page 2</h1>
<div class="links">
<nuxt-link to="page1">Page 1</nuxt-link>
<nuxt-link to="page2">Page 2</nuxt-link>
</div>
</div>
</template>
<script>
export default {
head() {
return {
title: 'Page 2',
};
},
}
</script>
Expected behavior: Page 1 will track “Page 1” as title Page 2 will track “Page 2” as title
Actual behavior: Page 1 & Page 2 tracks title correctly during initial load Page 2 tracks “Page 1” when changing route from Page 1 -> Page 2 Page 1 tracks “Page 2” when changing route from Page 2 -> Page 1
Console output:
location (&dl) http://localhost:3000/page2
page (&dp) /page2
title (&dt) Page 1
location (&dl) http://localhost:3000/page1
page (&dp) /page1
title (&dt) Page 2
<div align="right">This question is available on Nuxt.js community (#c8)</div>Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:50 (18 by maintainers)
Top Results From Across the Web
Vue meta not getting updates - Stack Overflow
This late update causes SEO not be presented by the time link being shared and validate. My full meta tags code metaInfo() {...
Read more >Server-Side Rendering (SSR) - Vue.js
Server-rendered markup doesn't need to wait until all JavaScript has been downloaded and executed to be displayed, so your user will see a...
Read more >How Nuxt.js solves the SEO problems in Vue.js
In the case of Vue.js, the meta tags are populated at the same time the JavaScript renders the page, so the bots may...
Read more >Vue.js SEO-Friendly SPAs: Tips, Tools & Prerender Example
It's a complete SPA that search engines might have a hard time crawling & indexing. Why is that? A single-page application adds content...
Read more >How to use Vue 3 Meta with Vue.js 3? - Laracasts
I am trying to use vue-meta with vue3 but its not working, ... @Tjyoung having same issue it only work on title where...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cool, maybe we should open an issue in the vue-meta repo? 😃 I’ve however found a workaround for anyone stumbling upon this issue. It does require a few things however:
I’m now getting the correct url’s and titles tracked on all pages.
@Jones-S WIP (in https://github.com/nuxt/vue-meta/)