鍍金池/ 問答/HTML5  HTML/ react-router 4.0 路由嵌套問題

react-router 4.0 路由嵌套問題

app.js(最外面組件)

<Router history={customHistory}>
                <div>
                    <Route  path="/layout" component={MyLayout}/>
                    <Route  path="/login" component={Login}/>
                </div>
</Router>

Login組件中沒有l(wèi)ayout布局,MyLayout組件中有左右布局的layout。

MyLayout組件

 <Layout>
  <HeaderCustom toggle={this.toggle} collapsed={this.state.collapsed} responsive={responsive} />
                    <Content  style={{ margin: '0 16px', overflow: 'initial' }}>
                             <Route   path="/" component={Home}/>
                            <Route  path="/config" component={Config}/>
                            <Route  path="/products" component={Category}/>
                            <Route  path="/products/:categoryId" component={Products}/>
                            <Route  path="/products/:categoryId/:productId" component={ProductDetail}/>
                            <Route  path="/news" component={News}/>
                            <Route  path="/data" component={Data}/>

                    </Content>
 <Layout>

設想是/layout的時候顯示Home組件,/layout/config顯示Config組件,/layout/products顯示Products組件??墒?code>/layout/config 和 /layout/products 都是顯示Home組件。

請問一下該如何修改代碼才能顯示正確?

回答
編輯回答
魚梓

<Route path="/layout/config" component={Config}/>
<Route path="/layout/products/:categoryId" component={Products}/>
react-router4需要寫完整的路徑吧

2017年11月9日 21:33
編輯回答
祈歡

Route exact path="/layout/" component={Home}/>

2018年8月3日 14:47
編輯回答
尐潴豬

我想問下,route直接寫在 Content 組件里面,和用Children來使用有什么區(qū)別?

2017年5月27日 15:07
編輯回答
葬愛
哈哈,抱歉,路徑寫完整試一下。。
2017年12月3日 06:33