catandmouse
catandmouse

Reputation: 11809

How to make `goBack()` method of history to ignore hash (#)?

I have some routes that are using /routename#somefilter. This is not a completely different route, it's just a filter flag we use.

However, whenever I access /routename#somefilter and click on the back button in our app, it goes back to /routename instead of an actual previous route (e.g. I came from /anotherroutename before going to /routename).

How do I make history from react-router ignore the hash routes? I am using useHistory() hook by the way.

Upvotes: 1

Views: 788

Answers (1)

Amit Chauhan
Amit Chauhan

Reputation: 6879

Instead of doing history.push use history.replace to update url. history.push add new entry to router history, so if you use history.replace, current entry in history.

Upvotes: 3

Related Questions