Skip to content

Make it easier to programmatically tell if a RouteLocationRaw is for the current route #2044

@AustinGrey

Description

@AustinGrey

What problem is this solving

When writing a menu, it's common to highlight or otherwise show as "active" the menu option which corresponds to the current route.

Libraries like PrimeVue allow you to specify a RouteLocationRaw when defining a menu option, as that's the "user facing" interface for defining a route to go to. So when writing your own menu, you need to somehow compare a RouteLocationRaw to the currentRoute, which is a RouteLocationNormalizedLoaded. But those two interfaces are wildly different, making comparison fraught with error.

VueRouter already must implement this comparison, since if you try to navigate to a RouteLocationRaw that goes to the same route, you get a navigation failure. But it doesn't expose any methods to allow this.

Proposed solution

Some ideas I have are:

  • Expose a method for turning a RouteLocationRaw into a RouteLocationNormalized, making comparison straightforward.
  • Add a router.test(route: RouteLocationRaw) method that lets you see what the result of navigation would be if you took it, but which does not cause any routing to actually happen.

Describe alternatives you've considered

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions