Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
history.push() actualiza la URL pero no representa el componente

Cuando trato de navegar por el historial de mi proyecto, parece que no funciona para renderizar otros componentes.

 import React from 'react'; import Login from './components/Login.jsx'; import Register from './components/Register'; import Apuntes from './components/Apuntes'; import history from './history/history'; import { Router } from 'react-router'; import { Route } from 'react-router-dom'; export function App() { return ( <Router history={history}> <Route exact path='/login' component={Login} /> <Route exact path='/register' component={Register} /> <Route exact path='/apuntes' component={Apuntes} /> </Router> ); }

Luego, en mi clase de inicio de sesión, llamo a history.push('/apuntes') y cambia la URL pero no hace nada más. El history.js es este:

 import { createBrowserHistory } from 'history'; export default createBrowserHistory();

Me gustaría saber cómo solucionar esto y hacer que muestre el componente según la URL.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

esto funcionará :)

 //import your components here import {BrowserRouter as Router,Route, Switch, useHistory } from "react-router-dom"; export function App() { const history = useHistory(); if (true) { // any condition you need here history.push("/login"); return ( <Switch> <Router> <Route exact path='/login'><Login/></Route> <Route exact path='/register'><Register/></Route> <Route exact path='/apuntes'><Apuntes/></Route> </Router> </Switch> ); }

además, puede definir una ruta como predeterminada agregando esta ruta al final de las rutas.

 <Route path="/"> <YourDefaultComponent/> </Route>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!