From c8b901ffa4b163cd89e86770a6f89c91ae3c9ac4 Mon Sep 17 00:00:00 2001 From: Sergio Arbeo Date: Fri, 8 Jun 2018 19:33:53 +0200 Subject: [PATCH] [BUGFIX beta] Better error when a route name is not valid Improves the error message shown when trying to define a route with a ':' in the name. Fixes #16642 (cherry picked from commit 13ca945f7d2227555a5df2a0766f8264d5152c8f) --- packages/ember-routing/lib/system/dsl.js | 5 +++++ packages/ember-routing/tests/system/dsl_test.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/ember-routing/lib/system/dsl.js b/packages/ember-routing/lib/system/dsl.js index d408a51130e..7a152ac1026 100644 --- a/packages/ember-routing/lib/system/dsl.js +++ b/packages/ember-routing/lib/system/dsl.js @@ -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, diff --git a/packages/ember-routing/tests/system/dsl_test.js b/packages/ember-routing/tests/system/dsl_test.js index f1f212dc26b..7d22a83d935 100644 --- a/packages/ember-routing/tests/system/dsl_test.js +++ b/packages/ember-routing/tests/system/dsl_test.js @@ -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() {