Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
cant access react-router params from parent route

I'm using react-router version 6.2.1. My router is setup like so in a Routes component:

const routes = isLoggedIn => [
  {
    path: '/',
    element: isLoggedIn ? <DashboardLayout /> : <Navigate to={LOGIN} /> ,
    children: [
      // redirect to homepage on null route (e.g. localhost:3000 with no trailing '/')
      { path: '', element: <Navigate to = {HOME} /> },
      { path: HOME, element: <Home /> },
      { path: LIBRARY,
        element: <Library/>,
        children: [
          {
            path: ':itemId',
            element: <ItemView/>
          }
        ] 
      }
  }
]

export default function Routes(props) {
  const loginStatus = props.loginStatus === LOGGED_IN;
  const routing = useRoutes(routes(loginStatus));

  return (
    <>
      {routing}
    </>
  );
}

I would like to access the itemId param in the url from a component that is in the Library component which is a parent route to the itemId. If i call the useParams hook from that parent route I do not see the itemId param. Why is this the case? Am i using the wrong version of react-router? According to this github pr I believe parent routes should have access to all params: https://github.com/remix-run/react-router/pull/7963

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!