1

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)?

4

1 回答 1

1

使用您当前的路由器映射,您拥有路由index.managelabel.notes. 当页面在 中刷新时index.manage,首先它会转换到父路由,在这种情况下是index,然后是manage。但是在你身上index你有重定向,所以管理没有被处理。

只需删除您的映射resource('index')并更新您的管理路线以反映新配置,因此链接index.manage将变为manage,并且 data-template-name=index/manage 将变为管理等。

更新后的路由映射如下:

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' });    
});

您可以保留您的 IndexRoute,因为 ember 默认创建一个this.route('index', { path: '/' }). 因此,您的 IndexRoute 将在用户转到时执行http://yoursite.com/

您可以在此 jsbin http://jsbin.com/ucanam/1024/edit中看到该示例的运行情况

于 2013-09-13T03:35:33.513 回答