Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda