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

How does universal router handle conflicts? #160

Open
johnnash03 opened this issue Nov 19, 2018 · 1 comment
Open

How does universal router handle conflicts? #160

johnnash03 opened this issue Nov 19, 2018 · 1 comment

Comments

@johnnash03
Copy link

How universal-router handles the following conflicting routes:

  1. /tickets/:filghtName-:flightNumber
  2. /tickets/seattle-washington
@frenzzy
Copy link
Member

frenzzy commented Nov 19, 2018

From API documentation: router.resolve() traverses the list of routes in the order they are defined until it finds the first route that matches provided URL path string and whose action function returns anything other than null or undefined.

I.e. the order of the routes matters and you probably need to specify the most specific routes first:

const routes = [
  { path: '/tickets/seattle-washington', action: () => 1 },
  { path: '/tickets/:filghtName-:flightNumber', action: () => 2 },
]
const router = new UniversalRouter(routes)
router.resolve('/tickets/seattle-washington') // => 1
router.resolve('/tickets/washington-seattle') // => 2

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