我想在页面启动之前看看我是否可以交换我的组件(一个在'默认'路由器视图中,另一个在'navDrawer'路由器视图中) . “交换”只是我实际想要实现的目标 .
最后,我想在加载整个页面之前将一个参数传递给组件,但显然组件是通过这个路由器加载的,我想在我决定传递给组件的道具之前预先检查(有没有防护) .
这是我的 routers/index.js
Landing
& LandingButtonBar
是组件 .
1 export default new Router({
2 routes: [
3 {
4 path: '/',
5 name: 'Landing',
6 components: {
7 default: Landing,
8 navDrawer: LandingButtonBar
9 },
10 // Guard
11 beforeEnter: (to, from, next) => {
// put some conditions here to invoke the next line.
12 next({
13 // path: '/', // this will obviously cause a recursion
14 components: {
15 default: LandingButtonBar,
16 navDrawer: Landing
}
})
}
}
]
})
一切都按预期工作 . 但我也希望组件在加载之前互相交换 . 这可能是使用 within routes 吗?
Attempt 1 :
自我指挥守卫的工作时间为0.01秒,但随后会陷入无限循环 . 即,取消注释第13行 . 在加载页面后,删除'path'属性也无效 . 失败 .