kriasoft/universal-router

How does universal router handle conflicts?

johnnash03 opened this issue · 1 comments

How universal-router handles the following conflicting routes:

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

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