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

130
Vistas
How to refresh the page when using a "Link to" in React router?

A bit new to react & I'm trying to make a simple linear page flow. When the link is clicked in the Login component, I want it to go to the Select page without displaying the previous page. At its current state, the link simply adds the Select page without refreshing anything.

App code:

import Login from "./pages/Login";
import Select from "./pages/Select";
import { createBrowserHistory } from 'history'
//import React from "react";
import {
    BrowserRouter as Router,
    Switch,
    Route,
    Link
} from "react-router-dom";

const history = createBrowserHistory()

function App() {
    return (
        <div className="fnb">
            <Router>
                <Switch>
                    <Route exact path="/" component={Login} />
                    <Route exact path="/select" component={Select} />
                </Switch>
            </Router>
        </div>
    );
}

export default App;

Login code:

import React from "react";
import {
    BrowserRouter as Router,
    Switch,
    Route,
    Link
} from "react-router-dom";
import Select from "./Select";

function Login() {
    return (
        <div>
            <p>
                this is the login
            </p>
            <Router>
                <Link to="/select" {window.location.reload();}>
                    go to select page
                </Link>

                <Switch>
                    <Route exact path="/select" component={Select}/>
                </Switch>
            </Router>
        </div>
    );
}

export default Login;

Select code:

import React from "react";

function Select() {
    return (
        <div>
            <header>
            <p>
                this is the select
            </p>
            </header>
        </div>
    );
}

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

0

https://stackoverflow.com/a/49162423/10787450 here is the answer. I think that exact param in the app component is the problem. Just remove it from Route.

about 4 years ago · Juan Pablo Isaza Denunciar

0

you change file code

App code.

//App code  
import React from 'react'
import { BrowserRouter as Router, Route } from 'react-router-dom'
import Login from './pages/Login'
import Select from './pages/Select'
const App = () => {
    return (
        <Router>
            <Route exact path='/' component={Login} />
            <Route path='/select' component={Select} />
        </Router>
    )
}

export default App

//Login code
import React from 'react'
import { Link } from 'react-router-dom'
const Login = () => {
    return (
        <div>
            <p>this is the login</p>
            <Link to='/select'>go to select page</Link>
        </div>
    )
}
export default Login

//select code.
import React from 'react'
const Select = () => {
    return (
        <div>
            <header>
                <p>this is the select</p>
            </header>
        </div>
    )
}

export default Select

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