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

238
Views
how to specify multiple parameters in path react-route-dom 6

tell me how in version 6 of the route - pass several values ​​​​to path in version 5 this could be done through an array

 <Routes>
           {token
               ?
              <Route path={'chat'} element={<Chat/>}/>
               :
             <Route path={'/'} element={<Login/>}/>}
   </Routes>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In react-router-dom v6 the Route component's path prop takes only a single string path value, not an array like previous versions did.

Route

declare function Route(
  props: RouteProps
): React.ReactElement | null;

interface RouteProps {
  caseSensitive?: boolean;
  children?: React.ReactNode;
  element?: React.ReactElement | null;
  index?: boolean;
  path?: string; // <-- string type only
}

You will need to render individual routes for each path.

Example:

<Route path='/' element={<Login />} />
<Route path='/home' element={<Login />} />
<Route path='/login' element={<Login />} />

Or abstract this utility into a function (not a component!) It needs to be a function call as only Route or React.Fragment components are valid children of the Routes component.

const renderPaths = (paths, Element) =>
  paths.map((path) => <Route key={path} path={path} element={Element} />);

...

<Routes>
  {renderPaths(["/", "/home", "/login"], <Login />)}
</Routes>

Edit how-can-i-add-multiple-path-for-home-page-with-react-router-dom-6 (forked)

about 4 years ago · Juan Pablo Isaza Report
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!