Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ReactJS React路由器将道具传递给孩子_Reactjs_React Router V4 - Fatal编程技术网

ReactJS React路由器将道具传递给孩子

ReactJS React路由器将道具传递给孩子,reactjs,react-router-v4,Reactjs,React Router V4,我有这个专用路由器,但我正努力从我的应用程序组件的状态中传递一个道具。有人能解释一下如何传入用户对象吗 <Route {...rest} render={(props) => authed === true ? <Component {...props} /> : <Redirect to={{pathname: '/login', state: {from: props.location}}} />} /> export d

我有这个专用路由器,但我正努力从我的应用程序组件的状态中传递一个道具。有人能解释一下如何传入用户对象吗

<Route
  {...rest}
  render={(props) => authed === true
    ? <Component {...props} />
    : <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>


export default class App extends Component {
state = {
authed: false,
loading: true,
user: false
}
authed===true
? 
: }
/>
导出默认类应用程序扩展组件{
状态={
作者:错,
加载:对,
用户:false
}

如果此路由位于App render方法内,则可以将其设置为:

<Route
  {...rest}
  render={(props) => this.state.authed === true
    ? <Component {...props} user={this.state.user} />
    : <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>
this.state.authed==true
? 
: }
/>

您的组件将获得react路由器道具(历史记录、匹配、位置)以及您在应用程序组件状态中维护的用户。

谢谢,如果它不在应用程序渲染方法中,我将如何执行?谢谢。如果outside表示它位于组件树中“下”的某个组件中,那么您必须将该用户作为道具传递下去,直到它到达您需要它的位置。