Refresh browser after route change in react router - reactjs

I am learning react-router for client-side routing in my basic webpage. I want to know how to refresh the browser once immediately after the route changes.
Is there a way to refresh the browser after the route changes using react-router?
Please do comment for more clarity if needed.
Note: Please provide suggestions for scenarios where react-router v4 is not used and an older version of react-router is used. (Just curious...........XD)

I was also searching for programmatically updating react router and found the best anwser which covers all router versions.
hope you will find this useful
https://stackoverflow.com/a/31079244/8542218
to refresh the page you can simply pass '/' or your home(landing) page route.

Related

Not able to route in reactjs

I am not getting how to link different pages in react js. I'm using react router through which by using link and route tags I'm able to change the url but not getting the content.
Can I get the answer as soon as possible..
Can you provide your code snippet?
There might be several reasons, maybe check the router nested settings, and see if it setup correct.

window.location.href vs redirect utility of react-router-dom

I have webapp written using React and React Router.
Are there any pros/cons of using window.location.href to redirect vs using the component provided via react-router?
Use history.push('/page-name') if you don't want the browser window to be reloaded, or window.location.href if you want to reload it. Usually when using the React Router the default behavior is using the history.push (this.props.history.push('/page-name') to be more specific, as the rest of the navigation through the application is already using React Route's <Link>, which has the same effect.
React-Router provides an interface for changing the URL either by modifying history or by using a Redirect component.
The React-Router interface is much more expressive than just manipulating window.location.href. I think the main pro of using React-Router is the added functionality, abstraction, and cleaner interface. Don't know that there are any real performance differences.

Refresh or Direct Url not working after bundle with webpack in react js?

I had an issue that the react js app with browser history only working on normal. But after build with webpack, i had an issue with refresh or paste relative url. If i'm using hash history instead of browser history it works well. I used several methods, but i'm only getting the issue
Mostly says this is a problem of tomcat server not webpack; If any one know to solve this issue please give a valid answers.
Note: I don't wanna use hash history, it's ugly for urls
You should only use browser history if you have a backend server supporting your application with routes.
If you're using webpack-dev-server (or any other) on a fully client side app you should use hash history
If you're using react-router v4 they are both accessible by BrowserRouter and HashRouter components.

Any cleaner way to trigger React Route change?

I am pretty new to React-Router, I wonder if there is a simple way to change Route, some concept like state in Angular UI Router. From the React Router official tutorial :
https://github.com/reactjs/react-router-tutorial/tree/master/lessons/12-navigating
My understanding is: I have to manually change the url to trigger route change.
What exactly are you trying to achieve? Did you take at look at the react-router Link component?
Perhaps the most used component in your app is Link. Its almost identical to the <a/> tag you're used to except that its aware of the Router it was rendered in.
React-Router Tutorial / Lesson 3: Navigating with Link

React-router: difference between history.push and location.href in flux app?

I'm a bit new with React, react-router, and flux, and I'm curious.
I'm curious, what's the difference between the 2 types of link click handling.
My feeling is location.href may "reset" the application, like if page was reloaded.
Is that right or wrong? And what's the difference between the 2 methods? Cause I'm not always able to use history.push in the application.
Thanks a lot in advance!
The HTML5 History API gives developers the ability to modify a website's URL without a full page refresh
whereas location.href will cause the page to refresh

Resources