Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Start with Ember.js Router
    primarykey
    data
    text
    <p>I want to learn using Ember.js for my next project. So far I have read the documentation <a href="http://emberjs.com/documentation/" rel="nofollow">here</a> but I saw no explanation about Router. Then I read the guide <a href="http://emberjs.com/guides/outlets/" rel="nofollow">here</a> but I still don't understand how to use Router properly. I tried using Router this way, I want 2 route:</p> <ol> <li><code>/login</code> which displays a button to enter the second route</li> <li><code>/home</code> which displays a button to enter the first route</li> </ol> <p>This is just a very simple code to test using Router to switch between "pages". I tried using this code but all I get is a blank page:</p> <pre><code>&lt;script src="js/libs/jquery-1.7.2.min.js"&gt;&lt;/script&gt; &lt;script src="js/libs/handlebars-1.0.0.beta.6.js"&gt;&lt;/script&gt; &lt;script src="js/libs/ember-1.0.pre.min.js"&gt;&lt;/script&gt; &lt;script&gt; var App = Ember.Application.create(); App.ApplicationController = Ember.Controller.extend(); App.ApplicationView = Ember.View.extend(); App.LoginView = Ember.View.extend({ templateName: 'login-page' }); App.HomeView = Ember.View.extend({ templateName: 'home-page' }); App.router = Ember.Router.create({ enableLogging: true, root: Ember.Route.extend({ index: Ember.Route.extend({ route: '/', redirectsTo: 'login' }), login: Ember.Route.extend({ route: '/login', doLogin: Ember.Route.transitionTo('home'), connectOutlets: function (router) { router.get('applicationController').connectOutlet('login'); } }), home: Ember.Route.extend({ route: '/home', doLogout: Ember.Route.transitionTo('login'), connectOutlets: function (router) { router.get('applicationController').connectOutlet('home'); } }) }) }); App.initialize(App.router); &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="login-page"&gt; &lt;h1&gt;Login Page&lt;/h1&gt; &lt;button {{action doLogin}}&gt;Login&lt;/button&gt; &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="home-page"&gt; &lt;h1&gt;Home Page&lt;/h1&gt; &lt;button {{action doLogout}}&gt;Logout&lt;/button&gt; &lt;/script&gt; </code></pre> <p>When I run this, the URL goes to <code>#/login</code> but it display nothing. Does anyone can show me how to make the above code works? Why do I get a blank page?</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.
    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