我试图将ShopPage组件中的CollectionPage组件显示为一个嵌套路由,该路由将collectionId作为参数接收,但得到一个空页面。这些是我的组件。
商店页面:
import React from 'react';
import CollectionsOverview from '../../components/collections-overview/collections-overview.component';
import { Route } from 'react-router-dom'
import CollectionPage from '../collection/collection.component';
const ShopPage = ({ match }) => (
<div className='shop-page'>
< Route exact path={`${match.path}`} component={CollectionsOverview} />
<Route exact path={`${match.path}/collectionId`} component={CollectionPage} />
</div>
)
export default ShopPage;CollectionPage组件:
import React from 'react';
import CollectionItem from '../../components/collection-item/collection-item.component';
import './collection.styles.scss';
const CollectionPage=({match})=>{
console.log(match);
return(
<div className="collection-page">
<h2>Collection Page</h2>
</div>
)}
export default CollectionPage;发布于 2020-09-03 19:46:53
似乎collectionId是一个应该以:为前缀的参数,如下所示:
<Route exact path={`${match.path}/:collectionId`} component={CollectionPage} />并将exact从App.tsx check this中的<Route path="/shop" component={ShopPage} />中删除
https://stackoverflow.com/questions/63722954
复制相似问题