1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【React】react-routerのhooks

Last updated at Posted at 2021-06-04

react-routerのhooksの種類

useHistory

  • ページ遷移させるときに使用するhistoryオブジェクトを取得できる
.ts
const history = useHistory();

history.push('/');
history.goBack();

useLocation

  • 現在のページのURLのpathやqueryなどを取得できる
.ts
const location = useLocation();

location.path
location.search

useParams

  • URLパラメータを取得できる
    • <Route path="/sample/:name"> と定義したページにアクセスした際に下記の記述で :name の値を取得できる
.ts
const { name } = useParams();
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?