Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias a route to another in a different branch #7

Open
rhyek opened this issue Feb 8, 2016 · 3 comments
Open

Alias a route to another in a different branch #7

rhyek opened this issue Feb 8, 2016 · 3 comments

Comments

@rhyek
Copy link

rhyek commented Feb 8, 2016

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', ?);
});
@nathanhammond
Copy link
Owner

This presently isn't possible. 😄 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!

@brumm
Copy link
Contributor

brumm commented Jun 21, 2016

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');

@nathanhammond
Copy link
Owner

nathanhammond commented Jun 21, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants