Skip to content

Commit

Permalink
[BUGFIX beta] Better error when a route name is not valid
Browse files Browse the repository at this point in the history
Improves the error message shown when trying to define
a route with a ':' in the name.

Fixes #16642

(cherry picked from commit 13ca945)
  • Loading branch information
Serabe authored and kategengler committed Jun 11, 2018
1 parent 3bac1d9 commit c8b901f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/ember-routing/lib/system/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class DSL {
})()
);

assert(
`'${name}' is not a valid route name. It cannot contain a ':'. You may want to use the 'path' option instead.`,
name.indexOf(':') === -1
);

if (this.enableLoadingSubstates) {
createRoute(this, `${name}_loading`, {
resetNamespace: options.resetNamespace,
Expand Down
13 changes: 13 additions & 0 deletions packages/ember-routing/tests/system/dsl_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ moduleFor(
});
}

['@test [GH#16642] better error when using a colon in a route name']() {
expectAssertion(() => {
Router = EmberRouter.extend();

Router.map(function() {
this.route('resource/:id');
});

let router = Router.create();
router._initRouterJs();
}, "'resource/:id' is not a valid route name. It cannot contain a ':'. You may want to use the 'path' option instead.");
}

['@test should retain resource namespace if nested with routes'](assert) {
Router = Router.map(function() {
this.route('bleep', function() {
Expand Down

0 comments on commit c8b901f

Please sign in to comment.