Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to re-render application template with new router?
    primarykey
    data
    text
    <h1>The code</h1> <p>I'm using the version <a href="https://github.com/emberjs/ember.js/tree/4fcdbf256039e8ca8d2647050e0c9a71234c922c">4fcdbf2560</a> with the new router.</p> <p>In my application, a user can be authenticated or not. The rendered template will not be the same depending on the authentication state.</p> <p>I've manage this by redefining the function <code>renderTemplate</code> in the <code>ApplicationRoute</code>:</p> <pre><code>App.ApplicationRoute = Ember.Route.extend({ renderTemplate: function() { this.render(App.authenticated() ? 'authenticated' : 'unauthenticated'); } }); </code></pre> <p>My router is quite simple:</p> <pre><code>App.Router.map(function(match) { match('/').to('index'); match('/sign').to('sign', function(match) { match('/in').to('signIn'); }); match('/dashboard').to('dashboard'); }); </code></pre> <p>The <code>IndexRoute</code> is just here to redirect the user depending on the authentication state:</p> <pre><code>App.IndexRoute = Ember.Route.extend({ redirect: function() { this.transitionTo(App.authenticated() ? 'dashboard' : 'signIn'); } }); </code></pre> <h1>The workflow</h1> <ol> <li>A user navigates to <code>/</code></li> <li>The <code>ApplicationRoute</code> is entered, as the user is not authenticated, the <code>unauthenticated</code> template is rendered</li> <li>The <code>IndexRoute</code> is entered, as the user is not authenticated, a redirection is made to <code>signIn</code></li> <li>The <code>signIn</code> template is rendered into its parent template -> the <code>unauthenticated</code> template</li> <li>The user sign in successfully, <code>route.transitionTo('dashboard')</code> is called</li> <li>The <code>dashboard</code> template is rendered into its parent template -> the <code>unauthenticated</code> template</li> </ol> <h1>The questions</h1> <ul> <li>What's wrong with my implementation ?</li> <li>Why does the <code>renderTemplate</code> function is not called when the <code>dashboard</code> template is rendered ?</li> <li>How can I force the application to re-render its template ?</li> </ul> <h1>Edit 2013-01-07</h1> <p>I've modified my code according to Evan's answer.</p> <p>My application template now looks like this:</p> <pre><code>{{#if isAuthenticated}} &lt;h1&gt;Authenticated&lt;/h1&gt; {{outlet}} {{else}} &lt;h1&gt;Unauthenticated&lt;/h1&gt; {{outlet}} {{/if}} </code></pre> <p>When the user lands on the application page, as he's not authenticated, it's the unauthenticated block which is rendered. Everything is working well except that nothing render into the <code>{{outlet}}</code> tag...</p> <p>But when my application template looks like this (=without conditional tags):</p> <pre><code>&lt;h1&gt;Unauthenticated&lt;/h1&gt; {{outlet}} </code></pre> <p>...it works ! So I wonder if the <code>{{outlet}}</code> tag can be inserted between conditional tags.</p>
    singulars
    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.
 

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