Skip to content

Instantly share code, notes, and snippets.

@zoghal
Forked from fpauser/index.html
Created July 1, 2012 07:00
Show Gist options
  • Save zoghal/3027240 to your computer and use it in GitHub Desktop.
Save zoghal/3027240 to your computer and use it in GitHub Desktop.
Ember.Router
<!doctype html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript' src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script type='text/javascript' src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
</head><body>
<script type="text/x-handlebars" data-template-name="application">
<h1>Application</h1>
<a href="#/dashboard">Dashboard</a>
<a href="#/users">Users</a>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="dashboard">
<h2>Dashboard</h2>
</script>
<script type="text/x-handlebars" data-template-name="users">
<h2>Users</h2>
</script>
<script type="text/javascript">
// App Namespace
var App = window.App = Ember.Application.create();
// Controllers
App.ApplicationController = Ember.Controller.extend();
App.DashboardController = Ember.Controller.extend();
App.UsersController = Ember.Controller.extend();
// Views
App.ApplicationView = Ember.View.extend({templateName: 'application'});
App.DashboardView = Ember.View.extend({templateName: 'dashboard'});
App.UsersView = Ember.View.extend({templateName: 'users'});
// Router
App.Router = Ember.Router.extend({
enableLogging: true,
location: 'hash',
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
redirectsTo: 'dashboard'
}),
dashboard: Ember.Route.extend({
route: '/dashboard',
connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet('dashboard');
}
}),
users: Ember.Route.extend({
route: '/users',
connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet('users');
}
})
})
});
// Initialize
App.initialize();
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment