This commit is contained in:
xsf 2016-08-25 15:36:30 +08:00
parent fe26bb679b
commit 4a86498619
2 changed files with 19 additions and 4 deletions

View File

@ -8,7 +8,8 @@ const VueRouter = require('vue-router');
const filters = require('./common/filters');// register filters 自定义过滤器
const _config = require('./common/config');// API接口 可以在需要的页面引入,此页面可以不引入!
console.log(_config.SERVICE.EDU.DETAILS);
//console.log(_config.SERVICE.EDU.DETAILS);
//Object.keys(filters).forEach(function(k) {
// Vue.filter(k, filters[k]);
@ -16,6 +17,7 @@ console.log(_config.SERVICE.EDU.DETAILS);
var App = Vue.extend(require('./app.vue'));
Vue.use(VueRouter);
var router = new VueRouter(
{
hashbang: true, //为true的时候 example.com/#!/foo/bar false的时候 example.com/#/foo/bar

View File

@ -23,18 +23,31 @@ module.exports = function(router){
name:'my_views',
component: require('./views/my_views.vue'),
},
'/login': {
name:'login',
component: require('./views/login.vue'),
},
});
window.routeList=[];
router.beforeEach(function(transition){
console.log('before---------------');
//可以通过在路由中的自定义字段来验证用户是否需要登陆
// console.log('通过配置路由中自定义的字段验证是否需要登陆');
if(transition.to.auth){
//alert(1);
console.log('通过配置路由中自定义的字段验证是否需要登陆');
if(localStorage.userId) {
transition.next();
} else {
var redirect = encodeURIComponent(transition.to.path);
transition.redirect('/login?redirect=' + redirect);
}
} else {
transition.next();
}
//如果是中止,这里可以判断用户登录
//if(transition.to.path === '/forbidden'){
if(transition.to.name == 'forbidden'){
@ -62,7 +75,7 @@ module.exports = function(router){
}
// setTimeout(function(){
transition.next();
// transition.next();
// },00);
});