Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After having inspected the router object again, I don't see any property in there that will allow you to grab the last route. In pre 4 there was a property for the last route, but it was a difficult property to work with.</p> <p>My solution is therefore the same as it was in pre 4: I'd create my own mixin to handle the routes that you navigate into, and from that list of routes, you can get whatever route you're after: the current one, the last one, et cetera...</p> <p>jsFiddle here: <a href="http://jsfiddle.net/sMtNG/">http://jsfiddle.net/sMtNG/</a></p> <p><strong>Mixin</strong></p> <p>The first thing to do is create the mixin that will allow us to push the routes into a <code>HistoryController</code>. We can do this by creating a <code>setupController</code> method which of course gets invoked every time you move into a route.</p> <pre><code>App.HistoryMixin = Ember.Mixin.create({ setupController: function() { this.controllerFor('history').pushObject(this.get('routeName')); } }); </code></pre> <p>We are pushing the route into the <code>HistoryController</code>.</p> <p><strong>History Controller</strong></p> <p>Since we're currently pushing the <code>routeName</code> into a non-existent <code>HistoryController</code>, we'll need to go ahead and create that, which is absolutely nothing special.</p> <pre><code>App.HistoryController = Ember.ArrayController.extend(); </code></pre> <p><strong>Index Controller</strong></p> <p>Since the <code>HistoryController</code> stores the list of routes we've navigated into, we'll need it accessible on other controllers, such as the <code>IndexController</code>, we'll therefore use <code>needs</code> to specify in which controller it should be accessible.</p> <pre><code>App.ApplicationController = Ember.Controller.extend({ needs: ['history'] }); </code></pre> <p><strong>Implement Mixin</strong></p> <p>We now have everything we need to keep a track of the routes, and so we'll specify that our routes need to implement this mixin.</p> <pre><code>App.CatRoute = Ember.Route.extend(App.HistoryMixin); </code></pre> <p><strong>Template</strong></p> <p>Last but not least, now that we have a <code>HistoryController</code> which our <code>IndexController</code> can access, and the mixin pushes each accessed route into the <code>HistoryController</code>, we can use our application view to output a list of the routes, and specify the last route. Of course in your case you'll need the last route minus one, but there's no sense in me doing everything!</p> <pre><code>&lt;h1&gt;Routes History ({{controllers.history.length}})&lt;/h1&gt; &lt;ul&gt; &lt;li&gt;Last Route: {{controllers.history.lastObject}}&lt;/li&gt; {{#each controllers.history}} &lt;li&gt;{{this}}&lt;/li&gt; {{/each}} &lt;/ul&gt; </code></pre> <p>I hope this gets you onto the straight and narrow.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload