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

153
Views
How to put <Route children={({match})} => ... > in Jsx fragment. React router dom v6

return ( <> Some jsx..

            <Route
                path={modal.info ? `/fullInfo/${this.state.modal.id}`:`/preview/${this.state.modal.id}`}
                element={({match}) => {
                    return (
                        <ModalWindow
                            modalVisible={Boolean(match)}
                            onCloseWindow={this.onCloseWindow}
                            modalContent={modal}
                        />
                    )
                }}
            />
            
        </>
    )

If I do that I get an error like: Route tag must be wrapped by Routes tag. I did this feature in a old version of react-router-dom but when I try to do it in the new one there is err..

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

0

In your App.js file, wrap the entire app with <BrowserRouter>

const AppWithRouter = () => <BrowserRouter><App /></BrowserRouter>
export default AppWithRouter

And then wrap all your routes in the new <Routes> tag (replaces switch):

<Routes>
  <Route path="..." element={...} />
</Routes>
about 4 years ago · Juan Pablo Isaza Report

0

The Routes component effectively replaced the Switch component from v5, and it's required to wrap any Route components. Additionally, the Route components no longer take component, and render and children prop functions, the routed components must use the element prop that takes a ReactElement, a.k.a. JSX.

Wrap the Route component in a Routes component and since all routes are always exactly matched, just render the ModalWindow with the modalVisible prop set to true.

return (
  <>
    ...Some jsx...
    <Routes>
      <Route
        path={modal.info
          ? `/fullInfo/${this.state.modal.id}`
          :`/preview/${this.state.modal.id}`
        }
        element={(
          <ModalWindow
            modalVisible
            onCloseWindow={this.onCloseWindow}
            modalContent={modal}
          />
        )}
      />
    </Routes>    
  </>
)
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!