yaakov
yaakov

Reputation: 4665

prevent 404 when using history.pushState

I'm using history.pushState() to display a different URL in the browser bar. However, the URL that is displayed does not actually exist. Therefore, if the user goes to a different page and then comes back, it will get a 404. Is there a way I can prevent this, maybe with htaccess?

Upvotes: 2

Views: 800

Answers (1)

thalesmello
thalesmello

Reputation: 3439

The main use for history.pushState is for you to keep track of the state of the page in your JavaScript application, so that your user can save that URL to get to that exact page some time in the future.

You can solve that problem by actually implementing the route you are pushing in the browser.

It could either be by server side or client side, just so you can ensure a good user experience.

Upvotes: 1

Related Questions