I'm developing a Backbone application with multiple views, collections, etc.. It also has a router that handles permanent URL pretty well.
What I'm trying to achieve is creating a "Back" button which allows user to go back window.history(-1)
to a previous view when it is available (user came from that view earlier). And if not, the "back" button would lead to the home page.
Basically I need to check whether or not Backbone has saved something in its history I can use to roll back one step. If the history is empty (we navigated to this URL directly) back point to the main router.
I already tried using window.hisory.length
but it is never empty. It may still point to the starting homepage of the browser or browser's blank opening page.
Does Backbone.History keeps track of the URLs (hashes) that passes through it? If so - how to I access it. I already tried console logging Backbone.History but found nothing I can hold on to.
Any help / advise is appreciated.