Vue-router: router.resolve does not use current route by default

Created on 14 Sep 2018  路  3Comments  路  Source: vuejs/vue-router

Version

3.0.1

Reproduction link

http://jsfiddle.net/df4Lnuw6/698/

Steps to reproduce

  • Click the link.
  • Click the button.

What is expected?

No warning to be shown.

What is actually happening?

A warning is shown saying that the id param was not provided. The docs mention that the current route will be used if omitted.

bug has PR

All 3 comments

In current implementation, this is how the resolve method is implemented https://github.com/vuejs/vue-router/blob/dev/src/index.js#L177 :

resolve (
    to: RawLocation,
    current?: Route,
    append?: boolean
  ): {
    location: Location,
    route: Route,
    href: string,
    // for backwards compat
    normalizedTo: Location,
    resolved: Route
  } {
    const location = normalizeLocation(
      to,
      current || this.history.current,
      append,
      this
    )
    const route = this.match(location, current)
    const fullPath = route.redirectedFrom || route.fullPath
    const base = this.history.base
    const href = createHref(base, fullPath, this.mode)
    return {
      location,
      route,
      href,
      // for backwards compat
      normalizedTo: location,
      resolved: route
    }
}

I am thinking the issue is coming from from line 195:
const route = this.match(location, current)

I am proposing this new implementation:

resolve (
    to: RawLocation,
    current?: Route,
    append?: boolean
  ): {
    location: Location,
    route: Route,
    href: string,
    // for backwards compat
    normalizedTo: Location,
    resolved: Route
  } {
    current = current || this.history.current

    const location = normalizeLocation(
      to,
      current,
      append,
      this
    )
    const route = this.match(location, current)
    const fullPath = route.redirectedFrom || route.fullPath
    const base = this.history.base
    const href = createHref(base, fullPath, this.mode)
    return {
      location,
      route,
      href,
      // for backwards compat
      normalizedTo: location,
      resolved: route
    }
}

Will love to receive feedbacks..

yeah, I remember I did this but somehow never committed the code nor created a PR...

Thanks :)

Was this page helpful?
0 / 5 - 0 ratings