kawagami
React Router 使用紀錄
Try
HackMD
kawagami
·
Follow
Last edited by
kawagami
on
Jun 26, 2021
Linked with GitHub
Contributed by
React Router 使用紀錄
預設已經設置好基本react環境
npm add react-router-dom
沒使用到react-router的所有功能,所以使用較輕量的react-router-dom
會使用到的有Route、BrowserRouter、Switch、Redirect、Link
BrowserRouter
較美觀的URL,相容性較HashRouter差一點點
Image Not Showing
Possible Reasons
The image file may be corrupted
The server hosting the image is unavailable
The image path is incorrect
The image format is not supported
Learn More →
HashRouter
帶#字號的URL,相容性較好
Switch
要切換內容的部份用Switch包住後就
不會
再往下尋找路徑
Route
在Switch中控制要顯示哪個pages
與Link的to相對應
Redirect
預設的頁面
Link
基本的Link,類似取代a連結
to 控制去到哪裡的路徑,與Route的path相對應
NavLink
有基本樣式的Link,此次使用中用來二次包裝的底板
MyNavLink
Image Not Showing
Possible Reasons
The image file may be corrupted
The server hosting the image is unavailable
The image path is incorrect
The image format is not supported
Learn More →
統一樣式,方便使用的客製化Link
為了避免BrowserRouter F5問題
在routes\web.php加入Route::view('/{path?}', 'index路徑');
React Router 使用紀錄
Expand all
Back to top
Go to bottom
React Router 使用紀錄
Expand all
Back to top
Go to bottom
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up
Comment