简体   繁体   English

嵌套路由不适用于反应路由器

[英]nested routing isn't working with react-router

I've been trying to render out CollectionPage and match the url with my page but my nested Route that's calling CollectionPage doesn't work for some reason!我一直在尝试渲染 CollectionPage 并将 url 与我的页面匹配,但是我调用 CollectionPage 的嵌套路由由于某种原因不起作用!

here's a snippet from my shop.component that is being called at app.js这是我在 app.js 中调用的 shop.component 中的一个片段

 import React from 'react'; import { Route } from 'react-router-dom'; import CollectionOverview from '.././../components/collections-overview/collections-overview.component'; import CollectionPage from '../collection/collection.component'; const ShopPage = ({ match }) => ( <div className='shop-page'> <Route exact path={`${match.path}`} component={CollectionOverview} /> <Route path={`${match.path}/:collectionId`} component={CollectionPage} /> </div> ); export default ShopPage;

When I did this course an issue I had was that in App.js I had set exact for the shop route.当我学习这门课程时,我遇到的一个问题是在 App.js 中我为商店路线设置了精确的。 Maybe you have it too :D也许你也有:D

我发现了发生了什么,在我的 app.js 中我不小心设置了我的 path='/shop/' 所以我只需要删除第二个 '/'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM