vue After logging in, all pages do not need to be logged in, and no login is required. The address of any page accessed is transferred to the login page to implement the idea.
The project uses vue2.0 axios,
高洛峰2017-05-19 10:38:19
Keywords:
Token-based authentication, JWT, axios interceptor
Link:
Reference link
黄舟2017-05-19 10:38:19
In the routing configuration, add the route that requires login
meta: { requiresAuth: true }
Determine whether the user is logged in in main.js, and jump to the login page if not logged in
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
//这里判断用户是否登录,我例子中是验证本地存储是否有token
if (!localStorage.token) {
next({
path: '/login',
query: { redirect: to.fullPath }
})
} else {
next()
}
} else {
next() // 确保一定要调用 next()
}
})
曾经蜡笔没有小新2017-05-19 10:38:19
Save the login status in local storage or cookie or vuex (preferably vuex), and then the rest is similar to the above