I have a few different cases where I’d like to define a redirect. As far as I can tell, the only way I can do that is by defining a subclass of Ember.Route
for each redirect with a setup
that calls this.replaceWith
. It would be really nice if the router offered a simple DSL. Something like
// People who bookmarked "/oldFoos" get the right page
router.redirect("/oldFoos", "/foos");
or
// Going to a user means going to her essays unless you specify a different tab:
router.redirect("/users/:id", function(params) {
return "/users/" + params.id + "/essays";
});
I have a prototype that works for these cases. It creates a new instance of Ember.Route
Ember.Route.create({
model: function(params) { return params; }
setup: function(params) { this.redirectTo(destination(params)); }
});
and generates a unique handler name for that route and map
s it.
Would anyone else have any use for this?