網站首頁 編程語言 正文
模糊匹配
<!-- 編寫路由鏈接 -->
<NavLink to="/home/a/b">Home</NavLink>
<!-- 注冊路由 -->
<Switch>
<Route path="/home" component={Home} />
</Switch>
點擊Home,進入路徑/home/a/b,此時模糊匹配到/home路徑的組件{Home}。
開啟嚴格匹配
<!-- 編寫路由鏈接 -->
<NavLink to="/home/a/b">Home</NavLink>
<!-- 注冊路由 -->
<Switch>
// 開啟嚴格匹配:exact={true}
<Route exact path="/home" component={Home} />
</Switch>
此時,點擊Home,進入路徑/home/a/b,無法匹配/home路徑下的{Home}組件。
1.默認使用的就是模糊匹配(簡單記:【輸入的路徑】必須包含要【匹配的路徑】,且順序要一致。
2.開啟嚴格匹配:
// 開啟嚴格匹配:exact={true}
<Route exact path="/home" component={Home} />
3.嚴格匹配不要隨便開啟,需要再開,有些時候開啟會導致無法繼續匹配二級路由
Redirect的使用
路由重定向
{/* 注冊路由 */}
<Switch>
<Route path="/about" component={About} />
<Route path="/home" component={Home} />
<Redirect to="/home" />
</Switch>
一般寫在所有路由注冊的最下方,當所有路由都無法匹配時,跳轉到Redirect指定的路由。
嵌套路由使用
注冊子路由時要寫上父路由的path值。 => /父路由path/子路由path。
路由的匹配是按照注冊路由的順序進行的。
src項目結構
├─App.jsx
├─index.js
├─pages
| ├─Home
| | ├─index.jsx
| | ├─News
| | | └index.jsx
| | ├─Message
| | | └index.jsx
| ├─About
| | └index.jsx
├─components
| ├─MyNavLink
| | └index.jsx
| ├─Header
| | └index.jsx
Message是Home的子組件,News組件是Home的子組件
例如:注冊Message組件時需要加上父路由Home的path值:/home/message
<Switch>
<Route path="/home/news" component={News} />
<Route path="/home/message" component={Message} />
<Redirect to="/home/news" />
</Switch>
原文鏈接:https://blog.csdn.net/Svik_zy/article/details/125676698?spm=1001.2014.3001.5502
相關推薦
- 2022-06-01 C語言超詳細解析函數棧幀_C 語言
- 2022-06-12 C語言數據結構中堆排序的分析總結_C 語言
- 2022-09-15 c語言實現向上取整計算方法_C 語言
- 2022-11-12 Python教程之成員和身份運算符的用法詳解_python
- 2022-03-15 pipe-platform-ops SpringCloudAlibaba日志鏈路追蹤和日志查詢系統
- 2022-09-14 python單鏈路性能測試實踐_python
- 2022-07-27 C++中this指針理解及作用_C 語言
- 2022-04-10 Blazor組件事件處理功能_基礎應用
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支