React Router 4嵌套路由

时间:2018-08-17 11:05:54

标签: react-router react-router-v4 react-router-dom

我正试图摆脱这个路由器的束缚,但我的静态应用程序(呈现DOM)出现问题。

我的设置如下:

<Router>
  <Switch>
    <Route exact path="/" component={Layout}>

      // these routes exist in {Layout} component
      <Route path="" component={Content} />
      <Route path="contact" component={Contact} />

    </Route>
    <Route path="/print" component={Print} />
  </Switch>
</Router>

期望的是,当用户位于/ {Layout}时,将使用{Content}进行渲染。当用户位于/ contact时,{Layout}将使用{Contact}进行渲染。而且,当用户位于/ print位置时,只会显示{Print}。

实际发生的是/和/ print可以正常工作,但/ contact不能正常工作(这将显示空白页)。如果我仅删除exact /有效,其余的更改路由,同时显示与/相同的内容。

感谢您的见识。

0 个答案:

没有答案
相关问题