2

In there a way in Ember.js with routing to basically create an alias route that simply goes to the same place as another route? I have the following defined:

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

An example working route looks like:

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

I need an alias routes though for each, without account, that should work in the form of:

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

Can I do something as simple as?

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

Thanks.

4

1 回答 1

2

您可以使用重定向到您想要重定向到的任何路由的方法设置概念上的别名路由以在redirect挂钩中重定向。transitionTo例子:

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

希望能帮助到你

于 2013-05-14T18:12:09.363 回答