我试图弄清楚如何使用 Vue 在同一条路线上拥有 2 个不同的组件。
主页或登录页面,取决于用户是否经过身份验证。
也许我在文档中遗漏了一些东西,但我无法也无法弄清楚。有可能吗?
Thx
在路由器映射中使用 auth 参数:
router.map({
'/home': {
component: Home,
auth: true
},
'/login': {
component: Login
},
'/something': {
component: Something,
auth: true
},
})
然后在每次转换之前检查:
router.beforeEach(function (transition) {
if (transition.to.auth && !auth.user.authenticated) {
transition.redirect('/login')
} else {
transition.next()
}
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)