3

So I've recently started playing around with createMemoryHistory because I'm building an app that'll be rendered inside an iframe. Fortunately, click on the UI buttons, I'm able to navigate around without modifying the url. However, when I click the "<-" (back) button in the browser, it modifies my url to the current path. Is there a way I can disable this s.t. clicking the back button doesn't change the url path but still maintains its behavior?

Thanks for your help!

//history.js
import createMemoryHistory from "history/createMemoryHistory";

const history = createMemoryHistory();

export default history;

I'm modifying history by doing history.push(something)

Tim
  • 2,221
  • 6
  • 22
  • 43

1 Answers1

1

In order to keep the url the same while still fire the history back behavior, you will probably need to override the default behavior of the browser back button with your desired behavior.

This link(how to stop browser back button using javascript) contains discussions on ways to achieve that. However, note that overriding default browser behavior possess certain risks and is not encouraged.

William He
  • 36
  • 1
  • 5