React 路由器 matchPath
问题。
我有一个网址:/users/test?dp=1
和路径为/users/:id
当我们传递到 react-router
的 matchpath
时,:id
给出 test?dp=1
。
我只想 test
作为输出。我不想更改 url
。
const match = matchPath("/users/test?dp=1", {
path: "/users/:id",
exact: true,
strict: false
});
console.log(match);
最佳答案
这里是 matchPath
的引用.
您需要使用 req.path
而不是 req.url
,后者包含 URL 的查询字符串部分。 matchPath
旨在仅接收不带查询字符串的path
。
您可以在这里看到相关内容: matchPath not working with queryParams in url #5285
关于javascript - React 路由器匹配路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62941293/