Static GitHub Issues

[1701] Is there any way to customize the 'beforeEach' hook of vue-router?

prev: Help Needed : Loading order incorrect with prefetch and preload, delayed boot time
next: [Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

I want to do login auth in spa mode by adding a 'beforeEach' hook of vue-router, and I have not found any description about the hook of vue-router in the doc of nuxt. Is there any way to customize the 'beforeEach' hook of vue-router?

The code works in a webpack template is like this:

import Router from 'vue-router'

const router = new Router({
    // ...
})

router.beforeEach((to, from, next) => {
  if(!localStorage.getItem('userId')) {
    next('/login');
  } else {
    next();
  }
}

new Vue({
    el: '#app',
    router,
    render: h => h(App)
}).$mount('#app')
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1524">#c1524</a>)</em></sub></div>