Param matchers greedy match defined routes
See original GitHub issueconst routes = [
{ name: 'home', path: '/' },
{ name: 'home.moo', path: 'moo' },
{ name: 'eviltroll', path: '/:catch' }
]
// Expect to match "home.moo"
router.matchPath('/moo')
// -> { name: 'eviltroll', params: { catch: 'moo' } ...
😦
I’m probably doing something wrong here, because this seems like quite an obvious use-case, defining one set of handlers for matching routes, and letting mis-hits continue through to the rest of the defined routes. What I didn’t expect was for the ‘param’ operator (eviltroll) to be greedy and match the route defined by the “home.moo” handler.
Is this expected behaviour? And if so, can the intended match above be reached some other way?
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Route Matching - Tutorial
A route has three attributes that determine whether or not it “matches” the URL: ... characters (greedy) until the next /, ?, or...
Read more >Broadcast channel routes are very greedy when matching ...
Broadcast channel routes are very greedy when matching parameter routes # ... While this sounds like it still matches the route definition, ...
Read more >Routing to controller actions in ASP.NET Core
ASP.NET Core controllers use the Routing middleware to match the URLs of incoming requests and map them to actions. Route templates:.
Read more >Routing Configuration - Documentation - SAPUI5 SDK
Each route defines a name, a pattern, and optionally one or more targets to which to navigate when the route has been matched....
Read more >What does the Express route param regex `(*)` mean?
I understand that the path is split on the slashes, so I thought I could use a regular expression in parentheses after the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks Thomas, understood. Will design for this consideration. #closing
To clarify: when two path definitions like
/mooand/:paramare siblings (they are children of the same parent node),/moois tried before/:param.The reason for not returning all matches and then picking the “best” one (i.e. the most specific one - with less params) is a design decision for increased performance and scalability: especially in the scenario of server-side rendering. That kind of match strategy is common server-side: the first match is the match.