ember-route-alias icon indicating copy to clipboard operation
ember-route-alias copied to clipboard

Alias a route to another in a different branch

Open rhyek opened this issue 9 years ago • 3 comments

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', ?);
});

rhyek avatar Feb 08 '16 05:02 rhyek

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!

nathanhammond avatar Feb 08 '16 08:02 nathanhammond

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 avatar Jun 21 '16 08:06 brumm

@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.

  1. Note that you never render the "foo.bar" route.
  2. 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.

nathanhammond avatar Jun 21 '16 15:06 nathanhammond