I have a resource, User
, within which there are several sections: posts
, following
, and followers
. There is some common logic in the UserRoute
, but there isn’t a standalone /users/:id
on the site. If you go to /users/:id
, I want to redirect (possibly dynamically, based on some information about the user in question) to one of the sub-routes. The only way I’ve figured out how to do this is to have separate resources with a good bit of duplication:
App.Router.map(function() {
this.resource('users');
this.route('user-details', { path: "/users/:id/:section" });
});
In UserRoute#setup
, I redirect to 'user-details'
with the default section.
Of course, I’d prefer to use a nested route:
App.Router.map(function() {
this.resource('users', function() {
this.route('details', { path: "/:section" });
});
});
The problem is that I can’t figure how how to determine – inside UserRoute#setup
– whether the route was activated because I went to /users/5633
(in which case I should redirect to /users/5633/posts
) or to /users/5633/following
(in which case I should just load the user data and let the UserDetailsRoute
handle the rendering).