1 - 单级路由
<NavLink to="/home">Home</NavLink>
<NavLink to="/about">about</NavLink>
<Routes>
<Route path='/home' element={<Home/>}/>
<Route path='/about' element={<About/>}/>
</Routes>
2 - 嵌套路由(about路径进行嵌套)
一级路由
<NavLink to="/home">Home</NavLink>
<NavLink to="/about">about</NavLink>
<Routes>
<Route path='/home' element={<Home/>}/>
<Route path='/about/*' element={<About/>}/>
</Routes>
二级路由
跳转按钮一般最好写完整,否则看代码看不清楚
<NavLink to="/about/news">新闻</NavLink>
<NavLink to="/about/message">消息</NavLink >
<Routes>
<Route path='news' element={<News/>}/>
<Route path='message' element={<Message/>}/>
</Routes>
跳转切换的path要写二级路由的路径
|