在vuejs router文档中,
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!auth.loggedIn()) {
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
} else {
next()
}
})
这段代码中的auth.loggedIn()这个方法应该写在那里?
还有就是这个query字段有什么用,没有也是可以的啊?
上面这个方法是自定义的,判断有没有登录用的。
to.fullPath
是当前页的路由地址。query
是为了登录成功之后可以根据query
中的内容跳转回原来的路由(页面)。