|
|
|
@ -110,7 +110,11 @@ const router = new VueRouter({
|
|
|
|
|
});
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
$('#loading').show();
|
|
|
|
|
console.log('before...')
|
|
|
|
|
console.log('store.state.accessToken', store.state.accessToken)
|
|
|
|
|
console.log('to.path', to.path)
|
|
|
|
|
if (!store.state.accessToken && to.path !== '/pages/login') {
|
|
|
|
|
console.log('router.push')
|
|
|
|
|
router.push('/pages/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -123,8 +127,11 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
route = routeList[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log('route', route)
|
|
|
|
|
if (!route) {
|
|
|
|
|
console.log('<<<!route to.path>>>', to.path)
|
|
|
|
|
var path = to.path === '/' ? '/pages/home' : to.path;
|
|
|
|
|
|
|
|
|
|
var url = path + '.js';
|
|
|
|
|
var method = path.replace(/\//g, '_').substr(1) + "()";
|
|
|
|
|
console.log('preRoute:from ' + from.path + ' to path ' + to.path);
|
|
|
|
@ -141,6 +148,7 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log('!route else', route)
|
|
|
|
|
console.log('route from:' + from.path + ' to:' + to.path);
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
@ -278,7 +286,9 @@ const app = new Vue({
|
|
|
|
|
},
|
|
|
|
|
mounted: function () {
|
|
|
|
|
console.log('mounted:app');
|
|
|
|
|
if(localStorage.getItem('userInfo') === null){
|
|
|
|
|
// 判断是否登录
|
|
|
|
|
if(localStorage.getItem('accessToken') === null){
|
|
|
|
|
//
|
|
|
|
|
router.push({path:'/pages/login'})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|