根据官方文档,给路由添加
"/my": {
component: My,
auth: true
},
并且
router.start(app, '#app');
router.beforeEach(function (transition) {
if (transition.to.auth) {
getUserInfo().then(function (user) {
if (!user.id) {
router.replace("/login")
}
});
} else {
transition.next()
}
});
在页面点击链接跳转,会重定向至/login 当直接复制 http://domin.com/my or http://xxx.com/!#/my 时 页面直接渲染,并不会进行验证?
路由配置
var router = new VueRouter({ history: true, //true false 均无效 saveScrollPosition: true //记住页面的滚动位置 html5模式适用 });
相关版本号
"vue": "^1.0.21",
"vue-async-data": "^1.0.2",
"vue-hot-reload-api": "^1.3.2",
"vue-html-loader": "^1.2.2",
"vue-loader": "^8.2.2",
"vue-resource": "^0.7.0",
"vue-router": "^0.7.13",
"vue-style-loader": "^1.0.0",
"vue-validator": "^2.0.1"