我想将数据从App.js文件传递到子类组件。我已经尝试过使用props,但是它根本无法正常工作
const org = 'Organization Dashboard'
const remotes = 'FromAdmin';
const DashboardContainer = ()=>(
<Sidebar org={org}>
<div className="App">
<Route path='/dashboard' component={Dashboard}/>
<Route path='/mytab' component={MyTab}/>
<Route path='/team' component={MyTeam}/>
<Route path='/settings' component={Settings}/>
<Route path='/logout' component={Logout}/>
<Route path='/team-settings/:param1' component={TeamSettings}/>
**<Route remotes='remotes' path='/user-settings/:param1' component={MyTab}/>**
</div>
</Sidebar>
)
当我在myTab中使用this.props时,我想在MyTab类组件中传递数据,
我们将不胜感激
答案 0 :(得分:3)
我假设您正在尝试将remotes='remotes'
传递给MyTab
。由Route
渲染的组件仅传递route props,但是您可以使用匿名内部函数插入额外的道具。 如果需要,别忘了传递路线道具!
<Route
path='/user-settings/:param1'
component={routeProps => <MyTab {...routeProps} remotes='remotes' />}
/>