JSFiddle - React, Tailwind, and code Playground
The objective here is to get the home view to render by default. So when the page is first loaded you should see 'welcome to my application'
HTML
<script src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
<script type="text/x-handlebars" data-template-name="home">
Welcome to my application!
</script>
<script type="text/x-handlebars" data-template-name="profile">
Check out my profile!
<ul>
<li><a {{action doOne}}>One</a><span> | </span></li>
<li><a {{action doTwo target="view"}}>Two</a></li>
</ul>
{{outlet section}}
</script>
<script type="text/x-handlebars" data-template-name="application">
<h1>My Ember Application</h1>
{{view App.NavbarView controllerBinding="controller.controllers.navbarController"}}
<div class="content">
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="navbar">
<ul>
<li><a {{action goHome}}>Home</a><span> | </span></li>
<li><a {{action viewProfile}}>My Profile</a></li>
</ul>
</script>
CSS
body {
padding: 2em;
}
h1 { font-size: 2em; }
a {
color: blue;
cursor: pointer;
}
.content {
padding: 1em;
}
ul {list-style-type:none;
margin:0;
padding:0;
}
ul li {display: inline}
JavaScript
App = Em.Application.create();
// Instantiated and wired up for you in App.initialize()
App.ApplicationController = Em.Controller.extend();
App.ApplicationView = Em.View.extend({ templateName: 'application' });
App.NavbarController = Em.Controller.extend();
App.NavbarView = Em.View.extend({ templateName: 'navbar' });
// Your stuff
App.HomeController = Em.Controller.extend({});
App.HomeView = Em.View.extend({ templateName: 'home' });
App.ProfileController = Em.Controller.extend({});
App.ProfileView = Em.View.extend({
templateName: 'profile',
doTwo: function() {
alert("hi");
}
});
App.Router = Em.Router.extend({
enableLogging: true,
location: 'hash',
root: Em.State.extend({
// EVENTS
goHome: Ember.State.transitionTo('home'),
viewProfile: Ember.State.transitionTo('profile'),
// STATES
index: Em.State.extend({
route: "/",
redirectsTo: 'home'
}),
home: Em.State.extend({
route: '/home',
connectOutlets: function(router, context) {
var appController = router.get('applicationController');
appController.connectOutlet('home');
}
}),
// STATES
profile: Em.State.extend({
route: '/profile',
connectOutlets: function(router, context) {
var appController = router.get('applicationController');
appController.connectOutlet('profile');
}
}),
doOne: function() {
alert("eins");
},
})
});
App.initialize();