DEV Community

Discussion on: A simple way to keep your Vue page title in sync with the router

Collapse
 
lpellis profile image
Loftie Ellis

Updating the title is definetly something a lot of spa's seems to neglect.
In your example you should probably specify immediate:true for the watch, otherwise the title wont update on the first load

watch: {
      '$route':{
        handler: (to, from) => {
          document.title = to.meta.title || 'Your Website'
        },
         immediate: true
      }
    },
Enter fullscreen mode Exit fullscreen mode

And if you start adding more metadata I would recommend looking at github.com/nuxt/vue-meta