universal-router
universal-router copied to clipboard
How does universal router handle conflicts?
How universal-router handles the following conflicting routes:
- /tickets/:filghtName-:flightNumber
- /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