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

Routing Namespaces - this.namespace() for defining routes #11308

Closed
wants to merge 1 commit into from

Conversation

jmurphyau
Copy link
Contributor

Adds this.namespace() to Router DSL along side this.route() and this.resource().

The new namespace function allows you to define a set of routes that exist under the
one namespace which isn't a parent route.

The following 2 examples produce the same results:

this.route('admin.users', { path: 'admin/users' });
this.route('admin.groups', { path: 'admin/groups' });
this.route('admin.environments', { path: 'admin/environments' });
this.namespace('admin', function() {
  this.route('users');
  this.route('groups');
  this.route('environments');
});

The above code examples create the following 3 routes:

  1. admin.users at the URL /admin/users
  2. admin.groups at the URL /admin/groups
  3. admin.environments at the URL /admin/environments

This differs to nested routes in that the following routes are not created/resolved/used:

  1. The parent route, admin
  2. admin.index
  3. admin.error
  4. admin.loading

@jayphelps
Copy link
Contributor

Just an FYI--With the big 2.0 push taking all the core team member's time, I imagine that's why there hasn't been a response from them. There are still features promised (routable components, etc) that haven't been delivered, so priorities and all that.

I personally like the general idea--I've used a helper in the past to achieve the same result.

@rwjblue
Copy link
Member

rwjblue commented Aug 2, 2015

Looks like this needs a rebase. I think in general I'm happy to land this behind a feature flag while things settle down for 2.0.0.

@jayphelps
Copy link
Contributor

@jmurphyau What is the intended rule for collisions?

this.namespace('foo', function () {
  this.route('bar');
});
this.route('foo', function () {
  this.route('car');
});

While obviously, one could say "don't do that", IMO that's not a good enough answer; the behavior should be defined and expected, even if that behavior is an exception or warning thrown.

@jmurphyau
Copy link
Contributor Author

@rwjblue awesome - i'll get onto that.

@jayphelps that an interesting scenario I haven't thought of.. not sure what it will do right now without any additional work but I would expect the this.route to overwrite the this.namespace - what are you thoughts?

I'll take a look into it

@jmurphyau jmurphyau force-pushed the router-namespace branch 2 times, most recently from 44ca8e9 to 197f474 Compare August 10, 2015 17:49
@jmurphyau
Copy link
Contributor Author

@jayphelps the default behaviour is that this.route overwrites this.namespace

I've added tests to explicitly point out this behaviour.

Also calls to this.route and this.namespace with different child routes defined will by default concatenates the child routes.. See test calls to this.route and this.namesapce with the same route should concatenate child routes

ok(router.router.recognizer.names['bleep.index'], 'index name under the parent name was not added');
});

QUnit.test('calls to this.route and this.namesapce with the same route should concatenate child routes', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"namesapce" is misspelled 😄

…) for defining routes

Adds this.namespace() to Router DSL along side this.route() and this.resource().

The new namespace function allows you to define a set of routes that exist under the
one namespace which isn't a parent route.

The following 2 examples produce the same results:

    this.route('admin.users', { path: 'admin/users' });
    this.route('admin.groups', { path: 'admin/groups' });
    this.route('admin.environments', { path: 'admin/environments' });

With this.namespace():

    this.namespace('admin', function() {
      this.route('users');
      this.route('groups');
      this.route('environments');
    });

The above code examples create the following 3 routes:

 1. `admin.users` at the URL `/admin/users`
 2. `admin.groups` at the URL `/admin/groups`
 3. `admin.environments` at the URL `/admin/environments`

This differs to nested routes in that the following routes are not created/resolved/used:

 1. The parent route, `admin`
 2. `admin.index`
 3. `admin.error`
 4. `admin.loading`
@jmurphyau
Copy link
Contributor Author

@jayphelps @rwjblue any different or additional thoughts on this? Going to rebase it shortly - hopefully its good to go after that

@rwjblue
Copy link
Member

rwjblue commented Apr 10, 2016

@jmurphyau - I think this needs to go through the RFC process. In general, I like this, but there are a few additional things that need to be fleshed out (that the RFC process is geared towards). Thank you very much for your work here, and I'm sorry for the crazy long delay here.

@rwjblue rwjblue closed this Apr 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants