Skip to content

Advanced Route-Matching #130

@summonmayank

Description

@summonmayank

Currently, raviger router does not support precedence matching. For example, if we have a route object that looks something like this:

{
      '/comp1/*': () => <h1>Just Comp-1</h1>,
      '/comp1/view2/*': () => <h1>Comp-1-view-2</h1>,
      '/comp1/view1/*': () => <h1>Comp-1-view1</h1>,
      '/comp2/*': () => <h1>Comp-2</h1>
}

If the app tries to route to /comp1/view1, instead of matching route /comp1/view1/* it matches /comp1/*. This can be fixed if we can reorder the routes in this object, like this:

{
      '/comp1/view2/*': () => <h1>Comp-1-view-2</h1>,
      '/comp1/view1/*': () => <h1>Comp-1-view1</h1>,
      '/comp1/*': () => <h1>Just Comp-1</h1>,
      '/comp2/*': () => <h1>Comp-2</h1>
}

The above works fine. But in some cases where we are dynamically creating this routes object, order cannot be maintained, since it's a javascript object which does not guarantee ordering when pushing new key-value pair.

It would be great if route precedence can be implemented. What does the community think ?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions