|
@@ -1,5 +1,6 @@
|
|
|
import Vue from 'vue'
|
|
|
import VueRouter from 'vue-router'
|
|
|
+import store from '@/store/index';
|
|
|
|
|
|
|
|
|
const originalPush = VueRouter.prototype.push
|
|
@@ -49,9 +50,9 @@ const routes = [
|
|
|
component: error404,
|
|
|
},
|
|
|
{
|
|
|
- path: '/login',
|
|
|
+ path: '/login',
|
|
|
meta: {
|
|
|
- requireAuth: true,
|
|
|
+ requireAuth: true,
|
|
|
},
|
|
|
name: 'login',
|
|
|
component: login,
|
|
@@ -73,16 +74,16 @@ const router = new VueRouter({
|
|
|
* **/
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
|
-
|
|
|
- if (to.matched.some(m => m.meta.requireAuth)) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (to.path !== '/login') {
|
|
|
- let token = window.localStorage.token;
|
|
|
- if (token === 'null' || token === '' || token === undefined){
|
|
|
- next()
|
|
|
- }
|
|
|
+ if(to.path === '/login' && store.getters.authToken){
|
|
|
+ next({path: '/'})
|
|
|
+ }else if (to.matched.some(m => m.meta.requireAuth)) {
|
|
|
+ if(window.localStorage.authToken){
|
|
|
+ next()
|
|
|
+ } else if (to.path !== '/login') {
|
|
|
+ let token = localStorage.getItem('authToken');
|
|
|
+ if (token === null || token === '' || token === undefined){
|
|
|
+ next({path: '/login'})
|
|
|
+ }else{next()}
|
|
|
} else {
|
|
|
next()
|
|
|
}
|