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" > </div> </div> ); } }
那么任何想法如何将ID传递给DetailsPage?