如何防止将两条路由与 react-router v4 匹配? [英] How to prevent matching two routes with react-router v4?
问题描述
我有以下两条路线:/items
和 /items/buy
.
I have the following two routes: /items
and /items/buy
.
每条路线对应于单个视图中的一个选项卡.两条路线都使用精确的道具呈现,但仍然有两个选项卡在导航到 /items/buy
时被标记为活动的.
Each route corresponds to a Tab in a single view. Both routes are rendered with an exact prop, but still, two tabs are being marked as active when navigating to /items/buy
.
我已经尝试使用 withRouter
,但我注意到将 /items
更改为 /items/sell
解决了问题,但我没有想要那条路线.
I already tried using withRouter
, but I noticed changing /items
to /items/sell
fixes the problem, but I don't wanna have that route.
我知道 rrv4 匹配我路线的第一部分 /items
和另一条路线 /items/buy
,但我认为这不应该发生,如果我正在使用 exact
.关于为什么会发生这种情况的任何线索?
I understand rrv4 is matching the first part of my route /items
and the other route too /items/buy
, but I think that shouldn't be happening if I'm using exact
. Any clues on why this is happening?
啊,我忘了说我已经在使用 Switch.
Ahh I forgot to say I am already using a Switch.
感谢您的帮助!
推荐答案
问题是我用 LinkContainer 包装 NavItem 而 LinkContainer 没有确切的道具.添加确切的道具解决了问题!
The problem was I was wrapping a NavItem with a LinkContainer and the LinkContainer did not have an exact prop. Adding the exact prop solved the issue!
这篇关于如何防止将两条路由与 react-router v4 匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!