universal-router icon indicating copy to clipboard operation
universal-router copied to clipboard

How does universal router handle conflicts?

Open johnnash03 opened this issue 6 years ago • 1 comments

How universal-router handles the following conflicting routes:

  1. /tickets/:filghtName-:flightNumber
  2. /tickets/seattle-washington

johnnash03 avatar Nov 19 '18 10:11 johnnash03

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

frenzzy avatar Nov 19 '18 11:11 frenzzy