dev
Branches
main (6.4.1)dev
Versions
6.4.1v4/5.xv3.x
useParams

useParams

Type declaration
declare function useParams<
  K extends string = string
>(): Readonly<Params<K>>;

The useParams hook returns an object of key/value pairs of the dynamic params from the current URL that were matched by the <Route path>. Child routes inherit all params from their parent routes.

import * as React from 'react';
import { Routes, Route, useParams } from 'react-router-dom';

function ProfilePage() {
  // Get the userId param from the URL.
  let { userId } = useParams();
  // ...
}

function App() {
  return (
    <Routes>
      <Route path="users">
        <Route path=":userId" element={<ProfilePage />} />
        <Route path="me" element={...} />
      </Route>
    </Routes>
  );
}
Docs and examples CC 4.0
Edit