Was the page navigated to using back or forward button?
window.performance.getEntriesByType("navigation").type === "back_forward";
This is how to detect if a page was loaded because the user navigated via back or forward buttons.
back_forwardif the navigation happened because of a back or forward navigation
navigateif the navigation happened because of a regular navigation event (like clicking a link).
reloadafter reloading the page
prerenderif the navigation has happened during a prerender hint