|
@@ -7,11 +7,11 @@ import baseRouters from './modules/base'
|
|
|
import businessRouters from './modules/business'
|
|
|
import { Message } from 'element-ui'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
-import 'nprogress/nprogress.css' // progress bar style
|
|
|
+import 'nprogress/nprogress.css' // progress bar style
|
|
|
import { getToken } from '@/utils/auth' // get token from cookie
|
|
|
+import store from '../store'
|
|
|
|
|
|
Vue.use(Router)
|
|
|
-
|
|
|
NProgress.configure({ showSpinner: true }) // NProgress Configuration
|
|
|
|
|
|
var routes = [
|
|
@@ -25,10 +25,17 @@ var routes = [
|
|
|
component: Home
|
|
|
},
|
|
|
...sysRouters,
|
|
|
- ...baseRouters,
|
|
|
- ...businessRouters
|
|
|
+ ...baseRouters
|
|
|
]
|
|
|
},
|
|
|
+ // 改为动态添加
|
|
|
+ // {
|
|
|
+ // path: '/buiness',
|
|
|
+ // component:Layout,
|
|
|
+ // children: [
|
|
|
+ // ...businessRouters
|
|
|
+ // ]
|
|
|
+ // },
|
|
|
{
|
|
|
path:'/',
|
|
|
redirect: '/home'
|
|
@@ -53,15 +60,30 @@ router.beforeEach((to, from, next) => {
|
|
|
const hasToken = getToken()
|
|
|
|
|
|
if (hasToken != null) {
|
|
|
- if (to.path === '/login') {
|
|
|
- // if is logged in, redirect to the home page
|
|
|
- next({ path: '/home' })
|
|
|
+ console.log(`loaded=${store.state.user.loaded}`);
|
|
|
+
|
|
|
+ if(!store.state.user.loaded){
|
|
|
+ // console.log(businessRouters);
|
|
|
+ router.addRoutes([{
|
|
|
+ path: '/business',
|
|
|
+ component:Layout,
|
|
|
+ children: businessRouters
|
|
|
+ }]);
|
|
|
+
|
|
|
+ store.commit("user/SET_LOADED",true);
|
|
|
+
|
|
|
+ //动态添加路由后
|
|
|
+ next({ ...to, replace: true })
|
|
|
}
|
|
|
- else {
|
|
|
- next();
|
|
|
+ else{
|
|
|
+ if (to.path === '/login') {
|
|
|
+ // if is logged in, redirect to the home page
|
|
|
+ next({ path: '/home' })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- NProgress.done();
|
|
|
}
|
|
|
else {
|
|
|
if (to.path === '/login') {
|
|
@@ -70,9 +92,9 @@ router.beforeEach((to, from, next) => {
|
|
|
else{
|
|
|
next(`/login?redirect=${to.path}`);
|
|
|
}
|
|
|
-
|
|
|
- NProgress.done();
|
|
|
}
|
|
|
+
|
|
|
+ //NProgress.done();
|
|
|
});
|
|
|
|
|
|
router.afterEach(() => {
|