Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Last active August 29, 2015 13:56
Show Gist options
  • Save jgwhite/8841164 to your computer and use it in GitHub Desktop.
Save jgwhite/8841164 to your computer and use it in GitHub Desktop.
App = Ember.Application.create();
App.Router.map(function () {
this.resource('user', function () {
this.route('links');
});
});
App.IndexRoute = Em.Route.extend({
beforeModel: function () {
this.transitionTo('user.links');
}
});
App.UserRoute = Em.Route.extend({
model: function () {
return new Ember.RSVP.Promise(function (resolve, reject) {
setTimeout(function () {
resolve({
name: 'Jo Smith',
links: [{
title: 'Google',
url: 'http://google.com/'
}, {
title: 'Example',
url: 'http://example.com/'
}]
});
}, 250);
});
}
});
App.UserIndexRoute = Em.Route.extend({
model: function () {
return this.modelFor('user');
}
});
App.UserLinksRoute = Em.Route.extend({
model: function () {
return this.modelFor('user').links;
}
});
body {
padding: 1em;
}
<script type="text/x-handlebars">
{{outlet}}
</script>
<script type="text/x-handlebars" id="user">
<h1>User</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" id="user/index">
<h2>Index</h2>
{{name}}
</script>
<script type="text/x-handlebars" id="user/links">
<h2>Links</h2>
<ul>
{{#each}}
<li><a {{bind-attr href=url}}>{{title}}</a></li>
{{/each}}
</ul>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment