Node.js/nuxt/路由

来自康健生活
Kangkk​(留言 | 贡献)2020年7月23日 (四) 10:48的版本 (创建页面,内容为“== router.beforeEach == 刷新白屏 == 组件独享守卫 == 刷新白屏 == middleware == 在需要鉴权的页面添加配置项: <code>middleware: 'auth'</code…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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')
    }
  })
}