My routes looks like this:
App.Router.map(function () {
this.resource('index', { path: '/' }, function() {
this.resource('label', { path: '/label' }, function() {
this.route('notes', { path: '/:label_id' });
});
this.route('manage', { path: '/manage' });
});
});
Users should only visit label.notes
and manage
routes. I'm trying to find solution how to implement redirection from index
for example to label.notes
. One of methods described in documentation is:
App.IndexRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('label.notes', 0);
}
});
Here is jsbin with full example http://jsbin.com/UnasOse/1/edit
This works if user navigates by clicking links, but if manage
opened by url, or page updated user will be redirected to notes
.
So, how to implement redirection only then user opens root url (index
)?
Using the your current router mapping, you have the routes index.manage
and label.notes
.
When the page is refreshed in the index.manage
, first it will transition to the parent route, in that case the index
, and after to manage
. But in you index
you have the redirect, so the manage isn't processed.
Just remove of your mapping the resource('index')
and update your manage route to reflect the new configuration, so link-to index.manage
will become manage
, and data-template-name=index/manage to manage etc.
The updated route mapping is the following:
App.Router.map(function () {
// this.route('index', { path: '/' }); generated by ember
this.resource('label', { path: '/label' }, function() {
this.route('notes', { path: '/:label_id' });
});
this.route('manage', { path: '/manage' });
});
You can keep your IndexRoute, because ember create by default a this.route('index', { path: '/' })
. So your IndexRoute will execute just when the user go to http://yoursite.com/
You can see that sample in action in this jsbin http://jsbin.com/ucanam/1024/edit