Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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
Javascript 在路由推送时响应路由器更新子组件_Javascript_Reactjs_React Router_React Router V4 - Fatal编程技术网

Javascript 在路由推送时响应路由器更新子组件

Javascript 在路由推送时响应路由器更新子组件,javascript,reactjs,react-router,react-router-v4,Javascript,Reactjs,React Router,React Router V4,我有一个这样的组件 class myApp extends React.Component { return ( <div> <NavigationBar /> {/* dynamic_content */} </div> ) } 更新动态内容,而不实际转换到其他组件 在伪代码中,我想要的是 class myApp extends React.Component { return ( <div>

我有一个这样的组件

class myApp extends React.Component {
  return (
   <div>
     <NavigationBar />
     {/* dynamic_content */}
   </div> )
}
更新
动态内容
,而不实际转换到其他组件
在伪代码中,我想要的是

class myApp extends React.Component {
  return (
   <div>
     <NavigationBar />
     {route === '/profile' -> <Profile/>
      route === '/notification' -> <Notification/>}
   </div> )
myApp类扩展了React.Component{ 返回( {route==='/profile'-> 路由==='/notification'->} ) 这可能吗?

我如何才能做到这一点?

是的,这是可能的,您需要定义嵌套路由,如

class MyApp extends React.Component {
  return (
   <div>
     <NavigationBar />
     {/* dynamic_content */}
     <Route path='/profile' component={Profile}/>
     <Route path="/notification" component={Notification}/>
   </div> )
}
此外,还必须以大写字符作为第一个字母来定义组件

class myApp extends React.Component {
  return (
   <div>
     <NavigationBar />
     {route === '/profile' -> <Profile/>
      route === '/notification' -> <Notification/>}
   </div> )
class MyApp extends React.Component {
  return (
   <div>
     <NavigationBar />
     {/* dynamic_content */}
     <Route path='/profile' component={Profile}/>
     <Route path="/notification" component={Notification}/>
   </div> )
}
<Router>
  <Route path="/" component={MyApp}/>
</Router>