【发布时间】:2020-09-08 16:13:43
【问题描述】:
react-router 在嵌套路由上出现问题。传递一个参数以适应任何后续链接,以便稍后在传递到 Route 的子组件中有条件地呈现
import React from "react";
import { Route } from "react-router-dom";
import CollectionsOverview from "../../components/collections-overview/collections-overview";
import CollectionPage from "../collection/collection";
const ShopPage = ({ match }) => {
return (
<div className="shop-page">
<Route exact path={`${match.path}`} component={CollectionsOverview} />
<Route path={`${match.path}/:collectionId`} component={CollectionPage} />
</div>
);
};
export default ShopPage;
import React from "react";
import "./collection.styles.scss";
const CollectionPage = ({ match }) => {
return (
<div className="collection-page">
<h2>COLLECTION PAGE: {match.params.collectionId}</h2>
</div>
);
};
export default CollectionPage;
Route 2 在路由操作时从不渲染其组件
【问题讨论】:
标签: javascript reactjs react-router