React router matchPath
issue.
I have a url: /users/test?dp=1
and path as /users/:id
When we pass to matchpath
of react-router
the :id
gives test?dp=1
.
I only want test
as the output. I do not want to change the url
.
const match = matchPath("/users/test?dp=1", {
path: "/users/:id",
exact: true,
strict: false
});
console.log(match);
Here is the reference on matchPath
.
What you'll want to do is use req.path
rather than req.url
, which includes the query string part of the URL. matchPath
is meant to receive only the path
without a query string.
You can see mention of that here: matchPath not working with queryParams in url #5285