2013-05-14 92 views
2

在那裏有一種方法在Ember.js路由基本上創建一個別名路由,簡單地去與另一個路由相同的地方?我有以下定義:Ember.js路由別名

this.resource("accounts", { path: "/accounts/:account_id" }, function() { 
    this.route("credit", { path: "/credits/:credit_id" }); 
    this.route("debit", { path: "/debits/:debit_id" }); 
    this.route("refund", { path: "/refunds/:refund_id" }); 
    this.route("hold", { path: "/holds/:hold_id" }); 
}); 

工作路線示例如下:

/accounts/foo-bar-account-id/credits/foo-bar-credit-id 

我需要一個別名路線,雖然每件都沒有帳戶,應在形式工作:

/credits/:credit_id 
/debits/:debit_id 
/refunds/:refund_id 
/holds/:hold_id 

我可以做一些簡單的事嗎?

this.route("accounts.credit", { path: "/credits/:credit_id" }); 
this.route("accounts.debit", { path: "/debits/:debit_id" }); 
this.route("accounts.refund", { path: "/refunds/:refund_id" }); 
this.route("accounts.hold", { path: "/holds/:hold_id" }); 

謝謝。

回答

2

您可以使用transitionTo方法將Alias路由設置爲在重定向到redirect掛鉤的概念上重定向到您想要重定向到的路由。例如:

App.IndexRoute = Ember.Route.extend({ 
    redirect: function() { 
    this.transitionTo('myAliasRoute'); 
    } 
}); 

希望它可以幫助

+0

會的路線是什麼樣的?我需要爲每個模板重複嗎? – Justin 2013-05-14 18:15:43

+0

嗯,我不這麼認爲,如果你正在做的唯一的事情是重定向,但還沒有測試過你的特例... – intuitivepixel 2013-05-14 18:18:06

+0

根據模板定義,這條路線是什麼樣子? 'this.route(「what-goes-here」,{path:「/ credits /:credit_id」});' – Justin 2013-05-14 18:21:29