简体   繁体   English

多组件反应路由器

[英]multiple component react router

I am building an index page of a react app. 我正在建立一个反应应用程序的索引页面。

The index page contains component A and B, if route is "/a" then I want to switch B with C and display A and C. For other routes "/a/b" , I want to display other pages. 索引页面包含组件A和B,如果路由为“ / a”,那么我想用C切换B并显示A和C。对于其他路由“ / a / b” ,我想显示其他页面。

I have tried the following but it is not working: 我已经尝试了以下方法,但是它不起作用:

<Route path="/" component={App}>
  <IndexRoute component={A} >
    <IndexRoute component={B}/>
    <Route path="/a" component={C} />
  </IndexRoute>
  <Route path="/a/b" component={D} />
</Route>

Thanks! 谢谢!

I solve it by an informal way. 我以非正式的方式解决。

<div>
    <Redirect from="/" to="home"/>
    <Route path="/" component={App}>
        <Route path="home" component={Home}>
            <IndexRoute component={IndexView} />
            <Route path="other" component={OtherView}></Route>
        </Route>
        <Route path="about" component={About}></Route>

    </Route>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM