(1) 從react-router-dom裡導入Switch,Route和Redirect元件:
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5SYmBjN2ImYiBjMwADNjNmYzcjY0kzMmVzM0kTN0QTMx8CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)
(2) 路徑/home指定成加載Home Component ,/detail則加載Detail Component.
檔案Home.jsx和Detail.jsx分别實作Component:
(3) 測試:url後加上/home,則加載home Component:
/detail元件的加載:
(1) 從react-router-dom裡導入Switch,Route和Redirect元件:
(2) 路徑/home指定成加載Home Component ,/detail則加載Detail Component.
檔案Home.jsx和Detail.jsx分别實作Component:
(3) 測試:url後加上/home,則加載home Component:
/detail元件的加載: