【发布时间】:2020-11-13 06:36:15
【问题描述】:
我正在尝试在用户未登录时设置重定向。但是当我像在我的示例中那样执行此操作时,URL 会更改,但我会从 nuxt 获得 This page could not be found。该代码位于 plugins 文件夹内的 login.js 中。然后我像这样将它包含在 nuxt 配置中。
plugins: [
'~/plugins/login.js'
],
这是处理重定向的实际代码
export default ({ app, store }) => {
app.router.beforeEach((to, from, next) => {
const loggedIn = store.state.account.loggedInAccount
if (!loggedIn) {
if (to.path !== '/redirect') {
next({ path: '/redirect' })
} else {
next()
}
} else {
next()
}
})
}
看起来路由还没有挂载。
【问题讨论】:
标签: vue.js nuxt.js vue-router