ember-route-alias
ember-route-alias copied to clipboard
Alias a route to another in a different branch
If I have route a/b/c, how could I alias x/y to it? Example:
this.route('a', function() {
this.route('b', function() {
this.route('c');
});
});
this.route('x', function() {
this.alias('y', '/y', ?);
});
This presently isn't possible. :smile: Noted as an enhancement. This isn't high on my priority list so if you wanted to add this you'd start by building and saving off a stack here: https://github.com/nathanhammond/ember-route-alias/blob/master/addon/initializers/route-alias.js#L50-L53. I'll gladly review a PR and help you along the way!
I came here to request this as well. In our case, we have a route that can appear as a top-level route as well as a sub-route.
this.route('foo', function() {
this.route('bar', { resetNamespace: true });
});
this.route('bar');
We also have two navigation buttons linking to foo and the top-level bar. Unfortunately, when top-level bar is active both links get an active class, because the top-level bar is actually linking to /foo/bar which matches on both buttons.
Ideally, we could do something like this:
this.route('foo', function() {
this.route('bar', { resetNamespace: true });
});
this.alias('bar', '/bar', 'foo.bar');
@brumm What you're doing in your first example will result in a collision. You can't resetNamespace to an additionally defined route. See this twiddle.
- Note that you never render the "foo.bar" route.
- Note that the result is different if you change the definition order inside of your router.js file.
In short the result is undefined behavior. Your ideal is actually something like this:
this.route('foo', function() {
this.route('bar');
});
this.alias('bar', '/bar', 'foo.bar');
This is exactly the goal of this issue, and still not high on my priority list. Still happy to guide somebody through a PR.