Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
Routing returns white page in React.js

I'm trying to set up routing but for some reason, it returns a blank page and renders nothing.

I'm using router version 6.3.0

// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from "react-router-dom";
import './index.css';
import App from './App';

ReactDOM.render(
  <React.StrictMode>
      <BrowserRouter><App /></BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);

// --------------------------------------------- //

// App.js

import React, { Component, Fragment } from "react";
import { Route } from "react-router-dom";
import Header from "./components/Landing/Header"
import Landing from "./components/Landing/Landing";
import Footer from "./components/Landing/Footer";


class App extends Component {
  render() {
    return (
      <Fragment>
        <Header />
            <Route path="/landing">
                <Landing />
            </Route>
        <Footer />
      </Fragment>
    );
  }
}

export default App;


// --------------------------------------------- //

// Landing.js

import Body from './Body'

function Landing(props) {
    return (
        <Body>
            <div className="Landing">
              Landing Context
            </div>
        </Body>
    )
}

export default Landing;

So when I visit http://localhost:3000/landing nothing is rendered, and when I try http://localhost:3000 nothing is rendered either.

If I remove the <Route></Route> part in App.js, it renders, but on any URL. What do I miss?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

react-router v6 has some breaking changes, it replaced Switch with Routes component:

/ index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from "react-router-dom";
import './index.css';
import App from './App';

ReactDOM.render(
  <React.StrictMode>
      <BrowserRouter><App /></BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);

// --------------------------------------------- //

// App.js

import React, { Component, Fragment } from "react";
import { Routes, Route } from "react-router-dom";
import Header from "./components/Landing/Header"
import Landing from "./components/Landing/Landing";
import Footer from "./components/Landing/Footer";


class App extends Component {
  render() {
    return (
      <Fragment>
            <Header />
                <Routes>  
                    <Route path="/landing" element={<Landing />}/>
                </Routes>
            <Footer />
      </Fragment>
    );
  }
}

export default App;

https://reactrouter.com/docs/en/v6/getting-started/overview

about 4 years ago · Juan Pablo Isaza Denunciar

0

As the OP is using react-router-dom v6

Instead of children, it is expecting element props to render the component.

https://reactrouter.com/docs/en/v6/getting-started/overview#configuring-routes

about 4 years ago · Juan Pablo Isaza Denunciar

0

In app.js wrap your route in router like this

import React, { Component, Fragment } from "react";
import { Router, Route } from "react-router-dom";
import Header from "./components/Landing/Header"
import Landing from "./components/Landing/Landing";
import Footer from "./components/Landing/Footer";


class App extends Component {
  render() {
    return (
      <Fragment>
        <Header />
            <Router>
              <Route path="/landing">
                <Landing />
              </Route>
            </Router>
        <Footer />
      </Fragment>
    );
  }
}

export default App;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda