Node.js/nuxt/路由
来自康健生活
router.beforeEach
刷新白屏
组件独享守卫
刷新白屏
middleware
在需要鉴权的页面添加配置项:
middleware: 'auth',
export default function ({ store, redirect }) {
// If the user is not authenticated
if (!store.state.authenticated) {
return redirect('/login')
}
}
export default function ({ $axios, redirect }) {
$axios.onRequest(config => {
console.log('Making request to ' + config.url)
})
$axios.onError(error => {
const code = parseInt(error.response && error.response.status)
if (code === 400) {
redirect('/400')
}
})
}
No categories