1
home/user/:id/friends/:id
function SomeComponent() {
  const { id } = useParams();
}

Which id will be used here? There are name conflicts.

1 Answers1

1

The last parameter of the path is the value that any component will see.

This is trivial to test.

Example:

const Component = () => {
  const { id } = useParams();

  return <h1>Id: {id}</h1>;
};

export default function App() {
  return (
    <div className="App">
      <Link to="/home/user/123/friends/456">Test?</Link>

      <Routes>
        <Route path="home/user/:id/friends/:id" element={<Component />} />
      </Routes>
    </div>
  );
}

Edit how-is-path-parameter-name-conflicts-handled-in-react-router-dom

enter image description here

Don't use the same path parameter twice in the same path string per route.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181