when writing a project, I encountered a problem, that is, I configured the interceptor and route interception, did not report an error, felt OK, but would log in to the page successfully, after manipulating the data, then habitually click to refresh, and then returned to the login page. I know that I cleared the stored value, but now I feel that if the user refreshes, I will go back to the login page, feeling that the mentality will explode!
// //
if (!store.state.username) {
router.push({
path: "/Login"
})
}
//
// storestatestate
router.beforeEach((to, from, next) => {
// eslint-disable-next-line eqeqeq
if (to.path === "/Login") {
sessionStorage.removeItem("username")
}
if (store.state.username) {
if (to.path === "/") {
next({
path: "/Member"
})
} else {
next()
}
} else {
next({
path: "/Login"
})
}
// eslint-disable-next-line eqeqeq
})
this is configured in main.js
// http
axios.interceptors.request.use(config => {
return config
}, error => {
return Promise.reject(error)
})
// http
axios.interceptors.response.use(data => {
// eslint-disable-next-line eqeqeq
if (data.data.code == 3) {
router.push({
path: "/Login",
query: {
redirect: location.hostname
}
})
sessionStorage.removeItem("username")
}
return data
}, error => {
return Promise.reject(error)
})
interceptor
with the help of the boss, what"s the problem? The
route doesn"t have a rediction. I don"t know what the problem is. Elsewhere, there"s no way to refresh and jump back to the login page!