I've encountered this issue in multiple apps, leading me to question if there's an error in my handling of Backbone history. The scenario is as follows...
There are two pages:
index.html
app.html
The index page is a standard HTML page with a link to app.html
. On the App page, Backbone.history.start()
initiates hash state management, allowing for toggling between two views on the App page:
app.html#search
app.html#results
Navigating between #search
and #results
pages works smoothly. However, the problem arises when attempting to navigate back to index.html
using the back button. The route back to the index page includes a stop at app.html
(without hash state), prompting the Backbone router to fill in the missing hash state, redirecting you back to app.html#search
. Subsequently, clicking the back button returns you to app.html
, triggering another fill-in of missing hash state... essentially trapping you in a loop and preventing a return to the previous page. This same issue occurs when utilizing push state.
This appears to be a common challenge with apps that automatically activate their routing system alongside a default page URL. Is there a recommended solution to circumvent this behavior?