Working on a website utilizing AJAX and the browser history API for navigation has been my recent project.
While I have successfully managed to implement navigation for the back/forward buttons, an issue arises when the page is refreshed.
The problem stems from storing a default state and page title, which gets overwritten upon page reload, leading to confusion during navigation.
For instance, if my history stack contains: [Index, page 1, page 2], and I refresh while on page 2, the default state changes to page 2. Subsequently, navigating back causes a loop between page 2 and page 1 due to the popstate handler going to the default page when the state is null.
This seems to be a common issue faced by many, yet clear solutions are hard to come by in tutorials that primarily focus on back/forward functionality rather than addressing problems caused by refreshing.
I am currently searching for a sustainable solution to this dilemma. Any suggestions or ideas would be greatly appreciated.