I am struggling to find any good Ember.js routing examples.
Should I use an addon like this or I personally like the look of this?
I see there is a routes collection as part of the State object but I cannot find any examples of how to use it.
Routing has been recently made available in core Ember.js, see Tom Dale's blog post.
Core developer Yehuda Katz wrote a gist about the usage of the new routing feature. It's a good read, and besides routing also states how it can be integrated with controllers.
To get the basic idea, here's a code example taken from the gist:
App.Router = Ember.Router.extend({
root: Ember.State.extend({
index: Ember.State.extend({
route: '/',
redirectsTo: 'calendar.index'
}),
calendar: Ember.State.extend({
route: '/calendar',
index: Ember.State.extend({
route: '/'
}),
preferences: Ember.State.extend({
route: '/preferences'
})
}),
mail: Ember.State.extend({
route: '/mail',
index: Ember.State.extend({
route: '/'
}),
preferences: Ember.State.extend({
route: '/preferences'
})
})
})
});
// If the user navigates to the page with the URL
// www.myapp.com/, you will start in the root.calendar.index state.
// The redirection to the calendar.index state will cause the URL
// to be updated to www.myapp.com/calendar
router.transitionTo('preferences');
// URL => www.myapp.com/calendar/preferences
router.transitionTo('mail.preferences');
// URL => www.myapp.com/mail/preferences
router.transitionTo('index');
// URL => www.myapp.com/mail
I use sproutcore-routing in my apps because:
For documentation have a look at the spoutcore-routing tests
I strongly recommend this guide on the ember site: http://emberjs.com/guides/router_primer/
I believe this content is very new-- I certainly didn't notice it a couple of weeks ago when I first started trying to understand Ember routing.
Ember routing changed entirely over Christmas. They posted some new documentation to help, but removed all the old tutorials. I'm guessing the old ways of doing things (in the previous answers) will be deprecated. http://emberjs.com/guides/routing/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With