【发布时间】:2020-12-22 15:37:53
【问题描述】:
我正在尝试将 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;
【问题讨论】:
-
您如何访问该页面?
-
所以
hats是一个参数 -
是的,我应该从我的 redux 状态动态获取该参数
-
从 App.tsx 中的
<Route path="/shop" component={ShopPage} />中删除exact检查 this
标签: reactjs react-router nested-routes