gpt4 book ai didi

vue.js - Vue-router:beforeEnter guard 对于子路径不能正常工作

转载 作者:搜寻专家 更新时间:2023-10-30 22:19:50 26 4
gpt4 key购买 nike

我正在尝试为我的子路由定义一个 beforeEnter 守卫,但我没有成功。这是我的路线配置:

  ...
{
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
},
...
]
}
...

当我刷新页面或直接在浏览器上插入 url 时一切正常(例如:base_path/path2)。但是,当我单击重定向到 path1 或 path2 的路由器链接时,beforeEnter 守卫不会执行。

我是不是理解错了什么?我需要为每个 child 设置一个 beforeEnter 守卫吗?

最佳答案

我找到的最佳解决方案是使用 beforeEach guard 而不是 beforeEnter。

beforeEnter 是一个 per route guard,然后它只应用于父路由,而不应用于子路由。

关于vue.js - Vue-router:beforeEnter guard 对于子路径不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46837819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com