Skip to content

Commit

Permalink
fix(components): fix:router-login-loginout-router-guard
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekQiaQia committed Jun 16, 2021
1 parent c6475ca commit 0b56d7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/layout/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default defineComponent({
}
const logout = () => {
// clear()
sessionStorage.removeItem('auth')
router.replace('/login')
}
return {
Expand Down
15 changes: 15 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,20 @@ const router = createRouter({
// end: false,

});
router.beforeEach((to, from, next) => {
console.log(to);
if(sessionStorage.getItem('auth')){
next()
}else if(to.path==='/login'){
next();
}else{
console.log('into login');
next({
path: '/login',
query: {redirect: to.fullPath}
})
}


});
export default router;
1 change: 1 addition & 0 deletions src/views/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default defineComponent({
.post('/api/auth/login', data)
.then((res) => {
if (res.data.code === 0) {
sessionStorage.setItem('auth', 'true')
router.push('/')
} else {
ElMessage({
Expand Down

0 comments on commit 0b56d7e

Please sign in to comment.