我试图点击一个嵌套的路由,但由于某种原因它没有达到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
组件没有被点击。我错过了什么?为什么这不起作用?
答案 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>
)