`useMatch` not able match more than one param
See original GitHub issueDescribe the bug
If my URL contains more than one param like /menu/:menuId/sub/:subId, useMatch will only return menuId when the route is match. I also use useMatchRoute to make sure that the route is really matches.
To Reproduce Steps to reproduce the behavior:
- Create a route that contains two params or more, like
/menu/:menuId/sub/:subId - In the corresponding route element, call
useMatch - And observe the params that return by
useMatch
Expected behavior
The useMatch should return both menuId & subId
Screenshots
Desktop (please complete the following information):
- OS: MacOS
- Browser: Microsoft Edge
- Version: 96.0.1054.43
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:12 (7 by maintainers)
Top Results From Across the Web
why is useMatch not working in React router? - Stack Overflow
I am trying to return the nearest current route match within the context of where it's called. I am quite new to react...
Read more >useMatch does not match against query params #1460 - GitHub
When using a Link that does routing with a query params such as routes.home({filter: "DASHBOARD"}), this matches for all home routes and ...
Read more >useMatch - Reach Router
useMatch. Matches a path to the location. Matching is relative to any parent Routers, but not parent match's, because they render even if...
Read more >Match - React Router: Declarative Routing for React.js
A match object contains information about how a <Route path> matched the URL. match objects contain the following properties: params - (object) Key/value ......
Read more >Use matchPath to Match Nested Route Paths in Parent Routes ...
In this lesson we'll use the `matchPath` function exported by react-router to find active nested routes inside of a parent component.
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

I personally find that the
useMatchesis quite difficult to use in scenarios like if I want to get all the match params. It would be great if we have something likeconst params = useParams().As for now, I created a custom hook to merge all the match params from
useMatches, it feels hacky, but works for meUh my bad, you are right, I’m actually confused by my current code setup. Yeah, it works as expected now👍