matchPath not working with queryParams in url
See original GitHub issueSo after reading https://github.com/ReactTraining/react-router/issues/4410 it looks like you can’t parse query params just by using react-router-v4.
I now have an issue that means my server-side data fetching doesn’t work (after following https://reacttraining.com/react-router/web/guides/server-rendering) because the matchPath function doesn’t match if you supply query params in the request?
Is there a solution for this?
Or have I simply encountered a bug relating to matchPath?
Example:
const routes = [
{
path: '/:locale/plp/.*',
component: PLPContainer,
loadData: props => {
return getData()
},
key: 'PLP'
},
...
];
export function collectServerSideCalls(routes, request) {
const promises = [];
routes.some(route => {
const match = matchPath(request.url, route);
if (match && route.loadData) {
promises.push(route.loadData(match));
}
return match;
});
return promises;
}
// When req.url = `/en-gb/plp`
const promises = collectServerSideCalls(routes, req)
// [ [Function] ]
// When req.url = `/en-gb/plp?fun=123`
const promises = collectServerSideCalls(routes, req)
// [ ]
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
matchPath not working with queryParams in url #5285 - GitHub
So after reading #4410 it looks like you can't parse query params just by using react-router-v4. I now have an issue that means...
Read more >React Router Match Path issue - Stack Overflow
matchPath is meant to receive only the path without a query string. ... of that here: matchPath not working with queryParams in url...
Read more >How to handle query params in React Router
In this part, we will learn how to handle query params in the URL. Lets create a new route for search page with...
Read more >matchPath - React Router v5
matchPath. This lets you use the same matching code that <Route> uses except outside of the normal render cycle, like gathering up data...
Read more >How to use the react-router.matchPath function in react-router
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
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

That’s a typo. You should be putting
request.pathinto matchPath (hence the name…)A PR would be the best way to get that fixed.