为什么我不能点击我的嵌套路线? ReactRouter4

时间:2017-12-18 21:15:17

标签: react-router-v4

我试图点击一个嵌套的路由,但由于某种原因它没有达到Component的渲染功能。这是我的路线档案:

const routes = (
  <Route path="/financefe" render={() => (
    <Normalize>
      <Switch>
        <Route path="/test" component={Test} />
      </Switch>
    </Normalize>
  )}/>
);

当我转到localhost:3000/financefe时,我点击了渲染功能。呈现Normalize个组件。然后我尝试转到localhost:3000/financefe/test,但Test组件没有被点击。我错过了什么?为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

react-router v4路由路径必须是绝对路径。这里是this article的一个例子,名为&#34;嵌套路线&#34;

const Main = () => (
  <main>
    <Switch>
      <Route exact path='/' component={Home}/>
      <Route path='/roster' component={Roster}/>
      <Route path='/schedule' component={Schedule}/>
    </Switch>
  </main>
)
const Roster = () => (
  <Switch>
    <Route exact path='/roster' component={FullRoster}/>
    <Route path='/roster/:number' component={Player}/>
  </Switch>
)