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>