鍍金池/ 問答/網(wǎng)絡安全  HTML/ react-router 4該怎么定義嵌套路由?

react-router 4該怎么定義嵌套路由?

請問怎么定義react-router 4的嵌套路由,我這樣定義是錯的,div里面包含switch,會定位不到,導致頁面空白:

return (
    <Router history={history}>
      <Switch>
        <Route exact path="/login"  component={Login} />
        <Route exact path="/signUp" component={SignUp} />
        <Route exact path="/forget" component={Forget} />
        <Route exact path="/weixinLogin" component={WeixinLogin} />
        <App>
          <Route exact path="/contacts/:organizationId/:uid/:ownerId"  component={Contact} />
          <Route exact path="/helpDetail/:id" component={HelpDetail} />
          <div>
            <Route exact path="/projects" component={Organization} />
            <Route exact path="/organizations/:organizationId/projects" component={Organization} />
            // 這是第一個 switch
            <Switch>
              {/*<Route exact path="/projects" component={Projects} />*/}
            </Switch>
          </div>
          <div>
            <Route path="/secretary"  component={Secretary} />
            // 下面switch里面的頁面都無法訪問到,是不是系統(tǒng)訪問到了第一個switch 然后沒有找到相應的頁面,但是switch的特性是其中之一,所以無法再向下查找??
            <Switch>
              <Route exact path="/secretary" component={SecretaryChat} />
              <Route exact path="/secretary/chat" component={Secretary} />
              <Route exact path="/secretary/log" component={SecretaryLog} />
              <Route exact path="/secretary/chatRecord" component={ChatRecord} />
            </Switch>
          </div>
        </App>
      </Switch>
    </Router>
  );

請問大神們 router4.0 版本的嵌套路由該怎么寫?

回答
編輯回答
熟稔

4.0的特點就是,在哪里定義的route,就在哪里渲染。然后就是switch不能嵌套使用,因為switch本來就是只選其一(名字不是亂定義的)。

2017年3月29日 23:24