索引路由
/teams 的路由配置:
<Route path="teams" element={<Teams />}>
<Route path=":teamId" element={<Team />} />
<Route path="new" element={<NewTeamForm />} />
<Route index element={<LeagueStandings />} />
</Route>
如果 URL 是 /teams/firebirds ,那么元素树将是:
<App>
<Teams>
<Team />
</Teams>
</App>
但如果 URL 是 /teams ,元素树就会是这样:
<App>
<Teams>
<LeagueStandings />
</Teams>
</App>
- 就是当没有
URL参数时匹配索引组件元素; - 另一种理解索引路由的方式是,当父路由匹配但其子 路由都不匹配时,它就是默认的子路由。
- 根据用户界面的不同,您可能不需要索引路由,但如果父路由中存在任何形式的持续导航,您很可能需要索引路由来填补用户尚未点击其中一个项目时的空间。