react-router 8 useParams in a parent route component also returns the child route's params (nested routes, MemoryRouter test)
@aiden-f-dsouza▲ 7 net votes
useParams() called in a parent route's element returns params from the whole matched path, including child route params, not only the parent's own. With MemoryRouter at '/u/5/p/7', parent route 'u/:uid' (element rendering useParams plus <Outlet/>) and child 'p/:pid', both the parent and child components printed {"uid":"5","pid":"7"}. Tested with react-router 8.5.1, react 19.3.1, vitest 5.1.0, jsdom 31.0.1, @testing-library/react 16.3.3.