10
React Router将参数传递给组件
const rootEl = document.getElementById('root'); ReactDOM.render( <BrowserRouter> <Switch> <Route exact path="/"> <MasterPage /> </Route> <Route exact path="/details/:id" > <DetailsPage /> </Route> </Switch> </BrowserRouter>, rootEl ); 我正在尝试访问DetailsPage组件中的ID,但无法访问它。我试过了 <DetailsPage foo={this.props}/> 将参数传递给DetailsPage,但徒劳。 export default class DetailsPage extends Component { constructor(props) { super(props); } render() { return ( <div className="page"> <Header /> <div id="mainContentContainer" > …