Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有关addRoute父子路由name、path相同时的处理结果问题 #2391

Closed
Mr-BeanSir opened this issue Oct 19, 2024 · 2 comments
Closed

Comments

@Mr-BeanSir
Copy link

Mr-BeanSir commented Oct 19, 2024

Reproduction

https://codesandbox.io/p/sandbox/vue-router-4-addroute-bug-4t7fyx

Steps to reproduce the bug

[Vue Router warn]: Finding ancestor route "/:path(.)" failed for "/:path(.)"

Expected behavior

在父路由被删除,matchers.lastIndexOf(insertionAncestor, upper - 1) 返回-1时,使用此路由的原本upper,而不是返回-1的upper

0 : {path: '/', redirect: undefined, name: undefined, meta: {…}, aliasOf: undefined, …}
1 : {path: '/:path(.*)*', redirect: undefined, name: 'ErrorPage', meta: {…}, aliasOf: undefined, …}

Actual behavior

0 : {path: '/:path(.*)*', redirect: undefined, name: 'ErrorPage', meta: {…}, aliasOf: undefined, …}
1 : {path: '/', redirect: undefined, name: undefined, meta: {…}, aliasOf: undefined, …}

Additional information

打开Reproduction,f12然后点击click here按钮,可以看到现在vue-router对于父子路由name,path相同时addRoute的处理结果

@posva
Copy link
Member

posva commented Oct 20, 2024

Duplicate of #2266

@posva posva marked this as a duplicate of #2266 Oct 20, 2024
@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2024
@Mr-BeanSir
Copy link
Author

Mr-BeanSir commented Oct 20, 2024

Duplicate of #2266

If the names are different, two routes will be created, as shown below

0: {path: '/', redirect: undefined, name: 'home', meta: {…}, aliasOf: undefined, …}
1: {path: '/:path(.*)*', redirect: undefined, name: 'ErrorPageSon', meta: {…}, aliasOf: undefined, …}
2: {path: '/:path(.*)*', redirect: undefined, name: ErrorPage, meta: {…}, aliasOf: undefined, …}

i hope my route list is clean,only has one ErrorPageSon route insert.
and i find,if have same name,but path different,it can be only created one route,maybe it's bug?look at the code below,removeRoute will remove parent route when insert child route.

export const RedirectRoute: RouteRecordRaw = {
  path: '/redirect',
  name: RedirectName,
  component: Layout,
  meta: {
    title: RedirectName,
    hideBreadcrumb: true,
  },
  children: [
    {
      path: ':path(.*)',
      name: RedirectName,
      component: () => import('@/views/redirect/index.vue'),
      meta: {
        title: RedirectName,
        hideBreadcrumb: true,
      },
    },
  ],
};

#2267 throw Error i think that reasonable for same name,This can help people know the specific cause of errors in the development environment
If it's just a warning, I think it's good to handle the routing better

The above is just my personal opinion. I just hope that my routing list can be cleaner and there will be no extra routes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants