Home > Net >  React history.push sending page request?
React history.push sending page request?

Time:09-01

I am running into a very sporadic issue. It doesn't happen often but, in our React application, history.push(URL) does not always work as intended.

Typically, history.push will be handled by the React UI to navigate between React routes - it won't send an actual page request for whatever the URL is. 99% of the time this works perfectly fine - however, we are seeing cases in which history.push(URL) is actually sending PAGE REQUESTS to the server. This results in a 404 Not Found error.

Here is the code snippet:

this.props.history.push(`/live?watchNow=true`)

In what scenario should this actually happen?

CodePudding user response:

You are changing the UI to /live route. Since React is a SPA (in case you do not use Server Side Rendering), it won't make a request for a new page to the server. But if you refresh the page with /live?watchNow=true, you browser will make a request to ressource/live?watchNow=true with parameter watchNow, nevertheless it should show up.

By the way push from useHistory do not make HTTP request (Docs), so check elsewhere.

  • Related