This commit is contained in:
xsf 2016-08-26 16:08:03 +08:00
parent cc3125026a
commit e5b0985b45
3 changed files with 11 additions and 37 deletions

View File

@ -29,12 +29,10 @@ module.exports = function(router){
},
});
window.routeList=[];
router.beforeEach(function(transition){
console.log('before---------------');
//可以通过在路由中的自定义字段来验证用户是否需要登陆
// console.log('通过配置路由中自定义的字段验证是否需要登陆');
if(transition.to.auth){
@ -48,37 +46,6 @@ module.exports = function(router){
transition.next();
}
//如果是中止,这里可以判断用户登录
//if(transition.to.path === '/forbidden'){
if(transition.to.name == 'forbidden'){
router.app.authenticating = true
setTimeout(function(){
router.app.authenticating = false
alert('此路由在全局中设置为中止');
transition.abort();
},1500);
}
if(routeList.length > 1 && transition.to.name==routeList[routeList.length-2]['name']){
router.app.effect='back';
routeList.splice(routeList.length-1,1);
console.log(routeList);
} else {
router.app.effect='fade';
routeList.push({
name : transition.to.name,
path : transition.to.path,
query : transition.to.query,
params : transition.to.params,
timer: +new Date
});
}
// setTimeout(function(){
// transition.next();
// },00);
});
//可以记录访问路径

View File

@ -14,13 +14,19 @@
<div class="index">
<h2>vue-router 介绍:</h2>
<a class="router-link" href="http://router.vuejs.org/zh-cn/" target="_blank">点击这里</a>
<mt-cell title="标题文字"></mt-cell>
<mt-cell title="标题文字" value="说明文字"></mt-cell>
</div>
</template>
<script>
var lifecycle = []; // canActivate this.lifecycle
import Vue from 'vue'
import { Cell } from 'mint-ui';
Vue.component(Cell.name, Cell);
module.exports = {
//props: [''],
data:function(){
@ -35,13 +41,13 @@
//waitForData: true, //
canActivate:function(transition){
//canActivate
lifecycle.push("route.canActivate <a href='http://vuejs.github.io/vue-router/zh-cn/pipeline/can-activate.html'>在验证阶段,当一个组件将要被切入的时候被调用。</a>");
console.log(1);
return true;
},
activate:function(transition){
//console.log('active');
this.lifecycle.push("route.activate <a href='http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html'>在激活阶段被调用,在 activate 被断定( resolved ,指该函数返回的 promise 被 resolve )。用于加载和设置当前组件的数据。</a>");
// this.$root.$set('header',this.title);
//this.$root.$set('header',this.title);
transition.next();
//apiafterActivate

View File

@ -1,6 +1,7 @@
<template>
<div>
Login page
看来汝方才点击的页面需要登录才能看呀~
页面还没写你自己看着搞搞把
</div>
</template>