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

197
Views
How to realize <Route children={({match})} => ... /> in a react-router-dom v6?

I have a modal which depended on a url.

my modal in jsx

<Route
    path={`/preview/${params.id}`}
    children={({match}) => {
        return (
            <ModalWindow
                modalVisible={Boolean(match)}
                onCloseWindow={onCloseWindow}
                modalContent={modal}
            />
        )
    }}
/>

I am getting an error A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.

But I already wrapped all my app in a tag.

export default function AppRouter() {
  return (
    <Routes>
        <Route 
            path={"/home"}
            element={<HomeApp />}
        />
        <Route 
            path={"/preview/:id"}
            exact
            element={<HomeApp />}
        />
         <Route
            path={"/fullInfo/:id"}
            exact
            element={<HomeApp />}
         />
        <Route
            path={"*"}
            render={<Navigate to="/home"/>}
        />
    </Routes>
  )
}

P.s I am new in react-router-dom of the new version.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to wrap the rendered element in the element prop of your Route.So instead of :

 <Route
      path={"*"}
      render={<Navigate to="/home"/>}
  />

Do this:

 <Route
      path={"*"}
      element={<Navigate to="/home"/>}
  />

It is the same for the modal Route, you should wrap the component in the element prop of the Route

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!