【发布时间】:2020-09-04 11:04:07
【问题描述】:
我的路线有问题。
我有这个代码:
<Switch>
<Route path="/Register" component={Register} />
<Route path="/:userId" component={UserProfile} />
<Route path="/direct/inbox" component={Messenger} />
在组件(UserProfile)中,我使用 useParams 来捕获 userId,但我的问题是当我尝试转到 /direct/inbox 时,它呈现 UserProfile 的组件(当然给我错误)。
所以我的问题是,如何在使用 :userId 时渲染其他路径???
***顺便说一句,寄存器的路径没有任何问题,它工作正常。
【问题讨论】:
-
我认为您必须将
:userId路由放在/direct/inbox路由之后的底部 -
这也行得通.. 不知道,谢谢