useParams trả về object chứa các dynamic segment của URL route đang active.
Ví dụ route /users/:id khi truy cập /users/42 thì const { id } = useParams() trả về id = '42'.
useParams returns an object containing the dynamic segments of the currently active URL route.
- For example, with route
/users/:idwhen visiting/users/42,const { id } = useParams()returnsid = '42'. - Note that values are always strings — convert manually if you need a number:
Number(id). - With TypeScript use
useParams<{ id: string }>()for type safety. - If called outside a Router context it returns an empty object.