|
|
@@ -4,7 +4,21 @@ import { getAccessToken } from '@/utils/auth'
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
const needAuth = to.meta.needAuth
|
|
|
const token = getAccessToken()
|
|
|
- if (to.path === '/login' && token !== null) {
|
|
|
+ if (needAuth) {
|
|
|
+ if (token == null) {
|
|
|
+ next('/login')
|
|
|
+ } else {
|
|
|
+ if (to.path === '/login') {
|
|
|
+ next({ path: '/' })
|
|
|
+ } else {
|
|
|
+ next()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ next()
|
|
|
+ }
|
|
|
+
|
|
|
+ /*if (to.path === '/login' && token !== null) {
|
|
|
next({ path: '/' })
|
|
|
} else {
|
|
|
next()
|
|
|
@@ -22,5 +36,5 @@ router.beforeEach((to, from, next) => {
|
|
|
if (token === null) {
|
|
|
next('/login')
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
})
|