[英]React router not rendering the correct component
I am having a weird problem with react routing and this might just be something stupid.我在反应路由方面遇到了一个奇怪的问题,这可能只是一些愚蠢的事情。 I a route /products
which renders a component.我是一个渲染组件的路由/products
。 Now I am trying to make another route /products/:id/confirmation-email
but react redirects me to the products component.现在我正在尝试创建另一条路线/products/:id/confirmation-email
但反应将我重定向到产品组件。 If I change either of the routes to something else it works fine.如果我将其中一条路线更改为其他路线,则效果很好。
<ProtectedRoute
path="/products"
component={Products}
/>
<ProtectedRoute
path="/products/:id/confirmation-email"
component={ConfirmationEmail}
/>
Try passing exact
props inside your route.尝试在您的路线内传递exact
道具。
<ProtectedRoute
exact
path="/products"
bootIntercom={bootIntercom}
trackPageVisitOnMixpanel={trackPageVisitOnMixpanel}
component={Products}
/>
<ProtectedRoute
exact
path="/products/:id/confirmation-email"
bootIntercom={bootIntercom}
trackPageVisitOnMixpanel={trackPageVisitOnMixpanel}
component={ConfirmationEmail}
Try moving the confirmation route above the products route in your code like this.尝试在您的代码中将确认路线移动到产品路线上方,如下所示。
<ProtectedRoute
path="/products/:id/confirmation-email"
bootIntercom={bootIntercom}
trackPageVisitOnMixpanel={trackPageVisitOnMixpanel}
component={ConfirmationEmail}
/>
<ProtectedRoute
path="/products"
bootIntercom={bootIntercom}
trackPageVisitOnMixpanel={trackPageVisitOnMixpanel}
component={Products}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.