ember.js - EmberJS: how to know if route was called because the user clicked the Back button -
i need know whether route called because user clicked browser button instead of clicking {{link-to}} link there. reason because of have filterable list pagination on associated template route. if user navigates away list , clicks button, designer wants state of filters in tact. however, if users clicks link arrive @ list, designer wants filter , pagination reset.
example:
1) users clicks 'books' navigation link , arrives @ '/books'. 2) user filters list goes page 2 of results. not update url , user still @ '/books'. 3) user clicks 1 of books , goes '/books/123'. 4) user clicks browser button , goes '/books'. need show filtered list @ page 2. 5) user clicks 'about us' link , goes '/about' 6) user clicks 'books' navigation link , arrives @ '/books'. time, user didn't click browser button arrive here, need reset filters , show list of unfiltered books on page 1.
in both step 4 , step 6, user arrives @ '/books' , booksroute, mechanism used arrive there differs, need show different books list result. there way tell if route called because button clicked instead of clicking hyperlink?
without saving state in url, i'd create dummy route eliminates books
state when accessed through link. (i assume controller you're keeping track of state).
this.resource('books', function(){ this.route('all'); });
route app.booksallroute = em.route.extend({ setupcontroller: function(){ var bookscontroller = this.controllerfor('books'); bookscontroller.set('filters', {}); // replacewith replaces history instead of adding additional history // may not necessary since we're doing mid transition // this.transitionto may more appropriate this.replacewith('books'); } });
template {{link-to 'books' 'books.all'}}
you might need move dummy route same level in router avoid having books model beingness populated. (i'm guessing how you're filtering results)
ember.js routes browser-history
No comments:
Post a Comment