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

131
Visualizações
React Router Dom rendering route error with loading components

I have a react project and I am working on navbar element of the project. I am currently implementing the react-router-dom in the project. I have the <Route/> nested in the <Routes/>. All of it is contained in the <BrowserRoutes/>. It is rendering the navbar. For the / it is supposed to check and see if loggedIn is true or false and display different components based on if it is true of false.

If it is false, it is supposed to show a login component with the login page. If the user is logged in, it is supposed to show the feed component.

Right now what it is doing is the user is not logged in but it is showing a blank screen and giving me the following error:

Uncaught Error: [LandingPage] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>

Here is the code I have:

import React, {useState} from 'react';
import Login from './Login';
import Signup from './Signup'
import LandingPage from './LandingPage'
import Feed from './Feed'
import axios from 'axios';
import { Routes, Route } from 'react-router-dom';

axios.defaults.baseURL = 'http://127.0.0.1:3333';
axios.defaults.headers.common['Authorization'] = 'AUTH TOKEN';
axios.defaults.headers.post['Content-Type'] = 'application/json';

export const ContentContext = React.createContext()

export default function App() {

  const [loggedIn, setLoggedIn] = useState(false)
  return (
    <div className="App">
      <ContentContext.Provider value={ContentContextValue}>
        <Routes>
          <Route exact path="/">
            {loggedIn ? <Feed /> : <LandingPage />}
          </Route>
          <Route exact path="/login" element={<Login/>}/>
          <Route exact path="/signup" element={<Signup/>}/>
        </Routes>
      </ContentContext.Provider>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just try to call the pages inside element for route, try like this:

<Route exact path="/" element={loggedIn ? <Feed /> : <LandingPage />} />
   
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