react router

https://github.com/ReactTraining/react-router/tree/master/packages/react-router-dom

安裝 react-router-dom

Switch 製作404

透過 router 改 state
需要把 組件封裝成 route

換頁動畫
TransitionGroup, CSSTransition
https://tylermcginnis.com/react-router-animated-transitions/

BrowserRouter 瀏覽器與伺服器需有相同設定
HashRouter 會在網址後面加上 # ,放到遠端子目錄也沒啥問題
createMemoryHistory 不會改網址,router資料都記錄在記憶體中

以下是筆記

但在使用這樣會 memory leak
<CSSTransition */}
{/* // 這行產生 memory leak
// key={location.key} */}

想要透過 props 傳送資料,需使用 HashRouter / BrowserRouter 再配合 render=
<Route exact path='/' render={(props) => <Home props={ props } loginCb={this.loginCb} />}/>

但使用 createMemoryHistory 時,會發生
Warning: You cannot change <Router history>

留言