react-router V4 路由嵌套后,父路由如何向子路由传递特定参数

以下是嵌套代码

ReactDOM.render(

  <HashRouter>

    <App>

      <Route path='/login' component={Login} />

    </App>

  </HashRouter>,

  document.getElementById('root')

父路由App的代码

constructor(props) {

    super(props);

    this.state = {

      userName: '123'

    }

  }

render() {

    return <div className="App">

      {this.props.children}

    </div>

   }

如何向子路由login传递userName这个参数?

PIPIONE
浏览 567回答 1
1回答

精慕HU

暂时用context来向子路由组件传递父路由state中的数据context用法
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript