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

304
Visualizações
React router dom throws invalid hook call, cannot read properties of null, etc
import './interface/App.css';
import { Home } from './interface/home';
import { Router, Route, Routes } from 'react-router-dom';

function App() {
  return ( 
    <div>
      <Router>
        <div>
          <Route exact path='/' component={Home}></Route>
        </div>
      </Router>
    </div>
  );

this throws

enter image description here enter image description here enter image description here

I have no idea why, I was following some tutorials and failed. I have tried using <Home/> instead of Home, I updated all my packages including react, react-dom, react-router-dom.

Any ideas why this is happening?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Issue

You are using react-router-dom@6 and using the low-level Router when you should import and use one of the high-level routers (BrowserRouter, MemoryRouter, etc) and you are using the RRDv5 Route component APIs. The Router component has a couple required props to make it work.

Router

declare function Router(
  props: RouterProps
): React.ReactElement | null;

interface RouterProps {
  basename?: string;
  children?: React.ReactNode;
  location: Partial<Location> | string;
  navigationType?: NavigationType;
  navigator: Navigator;
  static?: boolean;
}

Missing from your code are the required navigator and location props which feed into an internal location context the low-level router holds.

Solution

Import a high-level router, wrap the Route components in the Routes component, and render the routed content on the element prop as a ReactNode, a.k.a. JSX. component (and render and children function props`) are v5 and don't exist in v6.

The high-level routers maintain their own history/location contexts internally.

Example:

import './interface/App.css';
import { Home } from './interface/home';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';

function App() {
  return ( 
    <div>
      <Router>
        <div>
          <Routes>
            <Route path='/' element={<Home />} />
          </Routes>
        </div>
      </Router>
    </div>
  );
}
about 4 years ago · Santiago Gelvez 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