i'm developing backbone application multiple views, collections, etc.. has router handles permanent url pretty well.
what i'm trying achieve creating "back" button allows user go window.history(-1)
previous view when available (user came view earlier). , if not, "back" button lead home page.
basically need check whether or not backbone has saved in history can use roll 1 step. if history empty (we navigated url directly) point main router.
i tried using window.hisory.length
never empty. may still point starting homepage of browser or browser's blank opening page.
does backbone.history keeps track of urls (hashes) passes through it? if - how access it. tried console logging backbone.history found nothing can hold on to.
any / advise appreciated.
you can following:
router initialise function -
this.on("all", this.storeroute); this.history = [];
then storeroute function (also in router) -
storeroute: function() { return this.history.push(backbone.history.fragment); }
the in router -
previous: function(){ if (this.history.length > 1) { return this.navigate(this.history[this.history.length - 2], true); } }
so, can call yourapp.router.previous()
@ time!
Comments
Post a Comment