The following is the nested code
ReactDOM.render(
<HashRouter>
<App>
<Route path='/login' component={Login} />
</App>
</HashRouter>,
document.getElementById('root')
Code of parent routing App
constructor(props) {
super(props);
this.state = {
userName: '123'
}
}
render() {
return <p className="App">
{this.props.children}
</p>
}
How to pass the userName parameter to the sub-route login?
phpcn_u15822017-05-18 10:50:15
Temporarily use context to pass the data in the parent routing state to the child routing component
Context usage
为情所困2017-05-18 10:50:15
I don’t know how you want to achieve it. If you just bring data there, you can do this
/login/:userName
漂亮男人2017-05-18 10:50:15
If the routing component needs to pass parameters, the Route component should not set component, but render. Please read the react-router official documentation before deciding whether to ask questions.