Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reload a page with react-router?

I can see in this file (https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js) that there is a refresh function but I have no idea how to call it. I'm fairly new to react-router, I've only used it to move between some pages a couple times using hashHistory.

Right now I am trying to use it so that when an install fails, the user is given the option to 'retry' which I plan to execute by refreshing the page where the install happens (the page the user would be currently on). Any help would be appreciated.

This is a node app that runs on electron, not a web app.

like image 691
Sheriff Avatar asked Oct 18 '17 23:10

Sheriff


People also ask

How do you force reload the page in react?

To refresh page you don't need react-router, simple js: window. location. reload();

What does react-router provide to reloading of page?

react-router-dom allows us to navigate through different pages on our app with/without refreshing the entire component. By default, BrowserRouter in react-router-dom will not refresh the entire page.


2 Answers

firstly, add react-router as a dependency

`yarn add react-router` or `npm install react-router`  import { useHistory } from 'react-router' 

const history = useHistory()

/////then add this to the function that is called for re-rendering 

history.go(0)

This causes your page to re-render automatically

like image 65
sambalicious Avatar answered Oct 14 '22 19:10

sambalicious


You can use this to refresh Current route:

import createHistory from 'history/createBrowserHistory' const history = createHistory(); history.go(0) 
like image 43
Sumit Kumar Avatar answered Oct 14 '22 19:10

Sumit Kumar