[英]react-router doesn't send me to the right component
when i try to go to "shop/checkout/" i get the "/:current/:project" (i get ProjectPage and not CheckoutPage) what am I doing wrong?当我尝试去“shop/checkout/”时,我得到“/:current/:project”(我得到的是 ProjectPage 而不是 CheckoutPage)我做错了什么? the "/:current" is coming from the design component.
“/:current”来自设计组件。
<Switch location={location}>
<Route exact path="/design" component={Design} />
<Route exact path="/shop" component={Shop} />
<Route exact path="/:current/:project" component={ProjectPage}/>
<Route exact path="/shop/checkout" component={CheckoutPage}/>
</Switch>
design page:
<Link to={`${useLocation().pathname}/${title}`} />
//useLocation = "/design", ${title} is a project name, im maping through projects and when the user click a project it uses the name of the project to the url
shop:
<Link to="/shop/checkout">CHECKOUT</Link>
It's because shop and checkout are read as parameters.这是因为 shop 和 checkout 被读取为参数。 Then it renders the ProjectPage component.
然后它呈现 ProjectPage 组件。
Just put the /shop/checkout
route before your dynamic route with parameters.只需将
/shop/checkout
路由放在带有参数的动态路由之前。
<Switch location={location}>
<Route exact path="/design" component={Design} />
<Route exact path="/shop" component={Shop} />
<Route exact path="/shop/checkout" component={CheckoutPage}/>
<Route exact path="/:current/:project" component={ProjectPage}/>
</Switch>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.