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

155
Visualizações
How to use Route in React?

I'm learning from the Django rest framework + react tutorial. I have a problem, "App Component" is not showing up after entering the url address.

index.js :

import React from 'react';
import ReactDOM from 'react-dom';
import {Route, Link, Switch, BrowserRouter as Router} from "react-router-dom"
import './index.css';
import App from './App';

const routing = (
  <Router>
    <Route path="/app" component={App} />
  </Router>
);

ReactDOM.render(routing, document.getElementById('root'));

App.js

import React, { PureComponent } from 'react';

function App() {
  return ( 
    <div>
      <h1>App component</h1>
    </div>
   );
}

export default App;
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You are missing your Routes parent component: Please wrap it like this and replace component with element as its not working with router v6:

import {Routes, Route, Link, Switch, BrowserRouter} from "react-router-dom"

const routing = (
  <BrowserRouter>
    <Routes>
      <Route path="/app" element={<App />}></Route>
    </Routes>
  </BrowserRouter>
);
about 4 years ago · Juan Pablo Isaza Relatório

0

I don't see any overt issue in the shared code snippets.

react-router-dom v5

The snippets you shared are the v5 components and syntax.

import React from 'react';
import ReactDOM from 'react-dom';
import { Route, Link, Switch, BrowserRouter as Router } from "react-router-dom";
import './index.css';
import App from './App';

const routing = (
  <Router>
    <Route path="/app" component={App} />
  </Router>
);

ReactDOM.render(routing, document.getElementById('root'));

Edit how-to-use-route-in-react (react-router-dom v5)

react-router-dom v6

If you've somehow installed v6, then the Switch component was replaced by the Routes components, and now the Routes component must wrap any Route components. Another change is with the Route component API, there is no longer the component prop and render or children function props, all replaced by a single element prop that takes a ReactElement, or JSX, as a value.

import React from 'react';
import ReactDOM from 'react-dom';
import { Route, Link, Routes, BrowserRouter as Router } from "react-router-dom";
import './index.css';
import App from './App';

const routing = (
  <Router>
    <Routes>
      <Route path="/app" element={<App />} />
    </Routes>
  </Router>
);

ReactDOM.render(routing, document.getElementById('root'));

Edit how-to-use-route-in-react (react-router-dom v6)

about 4 years ago · Juan Pablo Isaza Relatório

0

Your routing is not a React component. Try this.

import React from 'react';
import ReactDOM from 'react-dom';
import {Route, Link, Switch, BrowserRouter as Router} from "react-router-dom"
import './index.css';
import App from './App';

const Routing = () => (
  <Router>
    <Route path="/app" component={App} />
  </Router>
);

ReactDOM.render(<Routing />, document.getElementById('root'));

You need to pass React Component to ReactDOM.render(...), and this is a React Component

const Routing = () => {
  return (...some jsx...)
}

# or short version
const Routing = () => (
  .... some jsx ....
)

This is not a React Component

const Routing = (
  ...some jsx...
)
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