1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React Router】useParamsについてまとめてみた

Last updated at Posted at 2025-09-22

はじめに

useParamsについて簡単にまとめてみました。

useParams とは?

「URLから必要な情報を簡単に取り出すために必要な道具」

たとえば、こんな URL があるとします:

/users/123

このとき「123」という数字は「ユーザーID」を表しています。
でも普通にコードを書いても、この「123」を自動で受け取ることはできません。

そこで useParams を使うと、

const { id } = useParams();

と書くだけで、

id = "123"

というふうに URL の一部を取り出せる ようになります。

もっと身近な例でいうと?

商品ページ /products/45 → 「商品番号 45 の情報」を取りたい

記事ページ /articles/99 → 「記事ID 99 の内容」を表示したい

ユーザーページ /users/123 → 「ユーザー123のプロフィール」を出したい

このような「URLごとに表示する内容が変わるページ」で、useParams が必須になります。

まとめ

「URL の中の :id や :name といった部分をコードで使えるようにする便利な仕組み」 が useParams です。

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?