react-router
TypeScriptのRouting library
Docs
Rotue
exact
pathとURLが正確に一致した時を示す
何のためにあるんだ?
全部に付けないと以下のような問題が起こる
以下の様なコードを書いた時に、/aboutにアクセスすると、/にも/aboutにもマッチし、両方共描画される
これを避けるためには、/の方にexactをつければいい
言うなれば、pathの文字数が少ないものはつけたほうがいい
code:tsx
<Route path="/" component={Home} />
<Route path="/about" component={About} />
全部につければ良いのでは?
History
github
history.goBack()とかあるの知らなかったmrsekut.icon*2 ref
remix-run/history
https://zenn.dev/stin/articles/how-to-develop-react-router
Hooksもある
https://reacttraining.com/react-router/web/api/Hooks
useParams
routerからパラメータを取得するやつ
型が利くのでこちらをつかいたい
#やりたいこと
<Link>で外部のサイトに行きたい
https://reacttraining.com/react-router/web/api/Link
結論: 無理
普通にaタグを使いましょう
ラッパーを作るといい
https://github.com/ReactTraining/react-router/issues/1147#issuecomment-283684226
react-router v6
参考
ささっと学ぶReact Router v4 – the2g
https://numb86-tech.hatenablog.com/entry/2019/11/03/184813
hooks
https://blog.uhy.ooo/entry/2020-06-10/react-router-location/