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

The path of the RouteConfig is the same as the alias content, which will cause an infinite loop. #2461

Comments

@chenfengjw163
Copy link
Contributor

Version

3.0.1

Reproduction link

https://codepen.io/chenfeng163/pen/qJzxGW

Steps to reproduce

The path of the RouteConfig is the same as the alias content

What is expected?

no error

What is actually happening?

infinite loop


The route of alias overrides the route of the path, causing the path and matchAs to be the same. When the url is parsed, an infinite loop occurs.

@chenfengjw163
Copy link
Contributor Author

chenfengjw163 commented Nov 1, 2018

PR #2462
before:

if (route.alias !== undefined) {
  const aliases = Array.isArray(route.alias)
    ? route.alias
    : [route.alias]

  aliases.forEach(alias => {
    const aliasRoute = {
      path: alias,
      children: route.children
    }
    addRouteRecord(
      pathList,
      pathMap,
      nameMap,
      aliasRoute,
      parent,
      record.path || '/' // matchAs
    )
  })
}

if (!pathMap[record.path]) {
  pathList.push(record.path)
  pathMap[record.path] = record
}

after:

if (!pathMap[record.path]) {
  pathList.push(record.path)
  pathMap[record.path] = record
}

if (route.alias !== undefined) {
  const aliases = Array.isArray(route.alias)
    ? route.alias
    : [route.alias]

  aliases.forEach(alias => {
    const aliasRoute = {
      path: alias,
      children: route.children
    }
    addRouteRecord(
      pathList,
      pathMap,
      nameMap,
      aliasRoute,
      parent,
      record.path || '/' // matchAs
    )
  })
}

@posva
Copy link
Member

posva commented Nov 7, 2018

I think a warning makes more sense here as I don't see a reason to have a path with the same value as an alias

@chenfengjw163
Copy link
Contributor Author

chenfengjw163 commented Nov 8, 2018

Yes, but the problem now is that if path and alias are the same, an error will be reported. In #2462 , I have added warning.

if (route.alias === path) {
  warn(
    false,
    `Path with the same value as an alias: ` +
    `{ path: "${path}" }`
  )
}

@posva posva added the has PR label Mar 26, 2019
@posva posva added this to Long term road (high prio, low complex) in Longterm Mar 26, 2019
@posva posva closed this as completed in 04a02c0 Jul 9, 2019
@posva posva moved this from Long term road (high prio, low complex) to Done in Longterm Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment