I am writing a Single Page Application in JavaScript. The URL changes but there are no page reloads. In my app I have a browser-like navigation with a back button, that actually runs window.back() . I also keep a backCounter variable (increased every time a user clicks on a link or goes back, listening to popstate) to make sure that the app back button doesn't let user go a blank tab.
I realise that ther are security implications when reading the history, and I have read answers here about it.
Question: is there a reliable way for me to know when the user has pressed "back" within the same SPA? I can think of two possible paths:
Neutralise. I could maybe neutralise the function of the back button by forcing a specific location on popstate
Integration. I would love to be able to know if the user has clicked on back or forward so that I can update backCounter accordingly.
...ideas?