close

[Solved] How do I reload a page with react-router?

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error How do I reload a page with react-router? in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How do I reload a page with react-router? Error Occurs?

Today I get the following error How do I reload a page with react-router? in javascript.

How To Solve How do I reload a page with react-router Error ?

  1. How To Solve How do I reload a page with react-router? Error ?

    To Solve How do I reload a page with react-router Error You can use this to refresh Current route:
    import createHistory from 'history/createBrowserHistory' const history = createHistory(); history.go(0)

  2. How do I reload a page with react-router?

    To Solve How do I reload a page with react-router Error You can use this to refresh Current route:
    import createHistory from 'history/createBrowserHistory' const history = createHistory(); history.go(0)

Solution 1

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

Solution 2

You can use this to refresh Current route:

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

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment