我想爲我的孩子路線定義一個beforeEnter後衛,但我沒有成功。這裏是我的路由配置:Vue-router:beforeEnter guard對於兒童路徑無法正常工作
...
{
path: '/',
component: App
beforeEnter: (to, from, next) ->
# This block is only reached when I refresh the page
children: [
{
name: 'component1',
path: '/component1',
components: component1
},
{
name: 'path2',
path: '/path2',
components: component2
},
...
]
}
...
一切工作正常,當我刷新頁面,或直接在瀏覽器(例如:BASE_PATH /路徑2)插入的URL。但是當我點擊重定向到path1或path2的路由器鏈接時,beforeEnter守護程序不會執行。
我明白什麼錯了嗎?我是否需要爲每個孩子設置一個beforeEnter後衛?