How do I reload a page with react-router?

react-router-dom refresh page
react router prevent page reload
react refresh page
react refresh page onclick
this.props.history.push refresh
react-router redirect
how to prevent page refresh in react js
forcerefresh 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.


You don't really need react-router for this. You can just use location.reload:

location.reload();

Also that version of react-router you linked to is very old, I think it's linking to v1 when it's currently on v4.

Basics of React Router v4, > A special version of the <Link> that will add styling attributes to the rendered element when it matches the current URL. Method 1: Refresh a Page Using JavaScript. The first way of refreshing a page or component is to use vanilla JavaScript to call the reload method to tell the browser to reload the current page: window.location.reload(false); This method takes an optional parameter which by default is false.


I guess that you're using react-router. I'll copy my answer from another post. So you have few possibilities to do that, currently my favorite way to do that is using anonymous function in component prop:

<Switch>
  <Route exact path="/" component={()=><HomeContainer/>} />
  <Route exact path="/file/:itemPath/:refHash" component={()=><File/>} />
  <Route exact path="/:folderName" component ={()=><Folder/>}/>
</Switch>

Or if you want to refresh with current url params, you'll need extra route (reload), and play a little with router stack:

reload = ()=>{
 const current = props.location.pathname;
 this.props.history.replace(`/reload`);
    setTimeout(() => {
      this.props.history.replace(current);
    });
}

<Switch>
  <Route path="/reload" component={null} key="reload" />
  <Route exact path="/" component={HomeContainer} />
  <Route exact path="/file/:itemPath/:refHash" component={File} />
  <Route exact path="/:folderName" component ={Folder}/>
</Switch>

<div onCLick={this.reload}>Reload</div>

How to Refresh a Page or Component in React, 6 Answers. I solved this by pushing a new route into history, then replacing that route with the current route (or the route you want to refresh). This will trigger react-router to "reload" the route without refreshing the entire page. React-Router is refreshing page when I follow a route using <a> tag. I'm building a React app that has links pointing to predefined routes. The routes resolve fine, but it's refreshing the page, thereby slowing down app performance.


You could try this workaround:

// I just wanted to reload a /messages page
history.pushState(null, '/');
history.pushState(null, '/messages');

Updating state of a parentless component in React, Or do you just want to re-render? The easiest way to reload the entire page is to just window.location.reload() . i want to reload the current page after updating some data in form , so i write like this: browserHistory.push('current page url'), but i find that it doesnt work . Skip to content ReactTraining / react-router


You can use this to refresh Current route:

import createHistory from 'history/createBrowserHistory'
const history = createHistory();
history.go(0)

react-router/NavLink.md at master · ReactTraining/react-router · GitHub, I stucked for days for this, I have problem getting the same path of route to refresh without using hard refresh eg. window.location.reload() to see  You can use window.location.reload(); in your componentDidMount() lifecycle method. If you are using react-router, it has a refresh method to do that. Edit: If you want to do that after a data update, you might be looking to a re-render not a reload and you can do that by using this.setState().


May be you are trying to push in history object, then bind your component with withrouter or use window.location.href = url to redirect ..

How to use react-router 4.0 to refresh current route? not reload the , When you click a navigation link created by React Router , it does not refresh the whole page if you are already on the page, instead, it simply  When you hit refresh, you bypass all of the React and React Router code. The server gets the request for /joblist and it must return something. On the server you need to pass the path that was requested to the run method in order for it to render the correct view. You can use the same route map,


how to reload a route? · Issue #1982 · ReactTraining/react-router , In React, there are two ways to refresh a page: updating the state and forcing a page reload. Let's explore both methods of using React to  in pure HTML if you click on a link pointing to the current page, the current page gets reloaded. with react-router it looks like a decision was made to not reload the current page, maybe for performance reasons or otherwise. This to me makes sense in some cases, don't get me wrong.


reload same page using react router · Issue #6312 · ReactTraining , (3) How to reload the page. The native window.location.reload() api. Untested, but perhaps something like this: function useSeamlessAppReload() { let appInfo​  Go to the page you want to refresh. Enter the address of the page you want to force refresh in the address bar at the top of your web browser. 3 Press and hold Ctrl on Windows or ⇧ Shift on Mac.


How to refresh data when using React Router <Link>, getElementById('root'); ReactDOM.render( <Router However, the replace('/'); sends you back to the home page but doesn't re-render any Note, if you press refresh on the browser the desired behaviour happens. React components will only re-render if the state or props are updated. If you try to navigate to the page you are currently on, and there isn't a change in state or props in that component, the component will not re-render/refresh. If you update the state/props of the component, or force the page to refresh, it will refresh.