|
|
@@ -12,14 +12,14 @@ let NPconfig = {
|
|
|
size: 2, // progress size
|
|
|
className: '' // progress custom class
|
|
|
};
|
|
|
-Vue.use(NProgress,NPconfig);
|
|
|
+Vue.use(NProgress, NPconfig);
|
|
|
|
|
|
const routes = [
|
|
|
{
|
|
|
path: '/',
|
|
|
name: '',
|
|
|
- component: () => import( '../page/index.vue'),
|
|
|
- meta: {index: 0},//meta对象的index用来定义当前路由的层级,由小到大,由低到高
|
|
|
+ component: () => import('../page/index.vue'),
|
|
|
+ meta: { index: 0 },//meta对象的index用来定义当前路由的层级,由小到大,由低到高
|
|
|
children: [
|
|
|
{
|
|
|
path: '/',
|
|
|
@@ -28,7 +28,7 @@ const routes = [
|
|
|
title: '预约课程',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/mainpage.vue')
|
|
|
+ component: () => import('../page/mainpage.vue')
|
|
|
},
|
|
|
{
|
|
|
path: '/appoint',
|
|
|
@@ -37,15 +37,15 @@ const routes = [
|
|
|
title: '预约课程',
|
|
|
index: 2
|
|
|
},
|
|
|
- component: () => import( '../page/appoint.vue')
|
|
|
- }, {
|
|
|
+ component: () => import('../page/appoint.vue')
|
|
|
+ }, {
|
|
|
path: '/record',
|
|
|
name: 'record',
|
|
|
meta: {
|
|
|
title: '预约记录',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/record.vue')
|
|
|
+ component: () => import('../page/record.vue')
|
|
|
}, {
|
|
|
path: '/mine',
|
|
|
name: 'mine',
|
|
|
@@ -53,15 +53,15 @@ const routes = [
|
|
|
title: '我的',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/mine.vue')
|
|
|
- },{
|
|
|
+ component: () => import('../page/mine.vue')
|
|
|
+ }, {
|
|
|
path: '/lesson',
|
|
|
name: 'lesson',
|
|
|
meta: {
|
|
|
title: '课程表',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/lesson.vue')
|
|
|
+ component: () => import('../page/lesson.vue')
|
|
|
},
|
|
|
]
|
|
|
},
|
|
|
@@ -72,7 +72,7 @@ const routes = [
|
|
|
title: '登陆',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/login.vue')
|
|
|
+ component: () => import('../page/login.vue')
|
|
|
// component: () => import( '../page/404.vue')
|
|
|
}, {
|
|
|
path: '/test',
|
|
|
@@ -81,15 +81,23 @@ const routes = [
|
|
|
title: 'test',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/test.vue')
|
|
|
- },{
|
|
|
+ component: () => import('../page/test.vue')
|
|
|
+ }, {
|
|
|
+ path: '/private',
|
|
|
+ name: 'private',
|
|
|
+ meta: {
|
|
|
+ title: 'private',
|
|
|
+ index: 1
|
|
|
+ },
|
|
|
+ component: () => import('../page/private.vue')
|
|
|
+ }, {
|
|
|
path: '/404',
|
|
|
name: '404',
|
|
|
meta: {
|
|
|
title: '404',
|
|
|
index: 1
|
|
|
},
|
|
|
- component: () => import( '../page/404.vue')
|
|
|
+ component: () => import('../page/404.vue')
|
|
|
}, {
|
|
|
path: '*',
|
|
|
name: 'notFound',
|
|
|
@@ -97,26 +105,26 @@ const routes = [
|
|
|
title: '404',
|
|
|
index: 3
|
|
|
},
|
|
|
- component: () => import( '../page/notFound.vue')
|
|
|
+ component: () => import('../page/notFound.vue')
|
|
|
},
|
|
|
];
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
- mode: 'history',
|
|
|
+ mode: 'history',
|
|
|
// mode: 'hash',
|
|
|
base: process.env.BASE_URL,
|
|
|
routes
|
|
|
});
|
|
|
|
|
|
// 路由守卫
|
|
|
-router.beforeEach((to,from,next)=>{
|
|
|
+router.beforeEach((to, from, next) => {
|
|
|
NProgress.start();
|
|
|
- const isLogin = localStorage.token? true : false;
|
|
|
- if(to.path == '/login' ){//'login'和'register'相当于是路由白名单
|
|
|
+ const isLogin = localStorage.token ? true : false;
|
|
|
+ if (to.path == '/login' || to.path == '/private') {//'login'和'register'相当于是路由白名单
|
|
|
next();
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//如果token存在,就正常跳转,如果不存在,则说明未登陆,则跳转到'login'
|
|
|
- isLogin? next() : next("/login");
|
|
|
+ isLogin ? next() : next("/login");
|
|
|
// next();
|
|
|
}
|
|
|
});
|