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

163
Vistas
react-router-dom does not display component

I'm trying to display my 'Home' component in my React project via react-router-dom. Thought I got your tone done right, I don't have a compile time error but the Home component just doesn't show up. Do you have an idea ?

App.js :

import Navbar from "./Components/Navbar";
import {
  BrowserRouter,
  Routes,
  Route
} from "react-router-dom";
import Home from "./Pages/Home";

function App() {
  return (
    <div className="App">
     <BrowserRouter>
        <Navbar />
        <Routes>
          <Route pathname="/" element={<Home />}> </Route>
        </Routes>
      </BrowserRouter>

    </div>
  );
}

export default App;

Home.js :

import React from "react";
import banner from "../assets/banner.jpg";
import {Link} from 'react-router-dom';
import '../Styles/Home.css';

function Home(){
    return (
        <div className="home" style={{ backgroundImage: `url(${banner})` }}>
            <div className="headerContainer">
                <h1>Food Corner</h1>
                <p>AMERICAN FOOD AT A CLICK.</p>
                <Link> 
                <button> Order Now </button>
                 </Link>
            </div>
        </div>
    );
}

export default Home;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If this is Router Router v6 (assuming since you are using <Routes>...</Routes>), the prop name is "path" and not "pathname"

So this:

<Route pathname="/" element={<Home />}> </Route>

Should be this:

<Route path="/" element={<Home />}> </Route>

Here are the docs for React-Router-Dom v6 (which is different than the v5 docs): Here

You should also change your react-router-dom imports. You should import BrowserRouter as Router like:

import { BrowserRouter as Router } from 'react-router-dom'
about 4 years ago · Juan Pablo Isaza Denunciar

0

You have a couple minor issues:

  1. The Route component uses a path prop, not a pathname prop. With no path prop there is no matching path and Home is not rendered.

    <Route path="/" element={<Home />} />
    
  2. The Link is missing what it's linking to, i.e. it is missing the to prop. This causes a TypeError: Cannot read properties of undefined (reading 'pathname') error. Add the to prop link destination. Example:

    <Link to="/order">
      <button> Order Now </button>
    </Link>
    

Edit react-router-dom-does-not-display-component

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