【发布时间】:2016-12-13 18:04:53
【问题描述】:
这是我的路由器的样子:
export default new VueRouter({
mode: 'history',
routes: [
/**
* Authentication
*/
{ name: 'login',
path: '/',
component: Login,
guest: true
},
{ name: 'registration',
path: '/registreer',
component: Registration,
guest: true
},
/**
* Forum
*/
{ name: 'forum',
path: '/forum',
component: Forum,
auth: true
},
]
});
现在我想在转到/forum 时获得auth 的值。我如何获得该值?我在the docs 中找不到任何内容。
已经试过了:
router.beforeEach((to, from, next) => {
console.log(to.auth);
next()
});
但是什么都没有出现,只有undefined。
有什么想法吗?
【问题讨论】:
-
你需要遍历matched routes。
-
你不能像你想要的那样设置密钥.. 使用 meta : {auth:true}
标签: vue.js vue-router