History API

UI.getCurrent().getPage().getHistory().back

That code will usually have the same behavior as the browser back button. However, it doesn’t always go back to exactly the same place the browser back goes. Shouldn’t it have the exact same behavior as the browser back?

I assume the page history is tracked automatically and no additional code is needed.

Hello, do you have by any chance a minimal example that demonstrates the browser vs. server-side history mismatch?

My code is definitely not minimal. I’ve also noticed that just like the History API code, the JavaScript that’s supposed to achieve the same result as the browser back doesn’t always go back to where the back button goes. Is the History API call just a wrapper for the JavaScript?

UI.getCurrent().getPage().executeJs("window.history.back()")

Brian Sheely:
My code is definitely not minimal. I’ve also noticed that just like the History API code, the JavaScript that’s supposed to achieve the same result as the browser back doesn’t always go back to where the back button goes. Is the History API call just a wrapper for the JavaScript?

UI.getCurrent().getPage().executeJs("window.history.back()")

Yep. You can find how it works right from the source: https://github.com/vaadin/flow/blob/master/flow-server/src/main/java/com/vaadin/flow/component/page/History.java; for example

    public void back() {
        ui.getPage().executeJs("history.back()");
    }