diff --git a/packages/ember-routing/lib/system/router.js b/packages/ember-routing/lib/system/router.js index 04ddbfef085..3e5e2fb9d88 100644 --- a/packages/ember-routing/lib/system/router.js +++ b/packages/ember-routing/lib/system/router.js @@ -262,7 +262,7 @@ const EmberRouter = EmberObject.extend(Evented, { if (DEBUG) { if (get(this, 'namespace').LOG_TRANSITIONS) { - // eslint-disable-next-line no-console + // eslint-disable-next-line no-console console.log(`Transitioned into '${EmberRouter._routePath(infos)}'`); } } @@ -336,7 +336,7 @@ const EmberRouter = EmberObject.extend(Evented, { if (DEBUG) { if (get(this, 'namespace').LOG_TRANSITIONS) { - // eslint-disable-next-line no-console + // eslint-disable-next-line no-console console.log(`Preparing to transition from '${EmberRouter._routePath(oldInfos)}' to '${EmberRouter._routePath(newInfos)}'`); } } @@ -373,9 +373,11 @@ const EmberRouter = EmberObject.extend(Evented, { */ transitionTo(...args) { if (resemblesURL(args[0])) { + assert(`A transition was attempted from '${this.currentRouteName}' to '${args[0]}' but the application instance has already been destroyed.`, !this.isDestroying && !this.isDestroyed); return this._doURLTransition('transitionTo', args[0]); } let { routeName, models, queryParams } = extractRouteArgs(args); + assert(`A transition was attempted from '${this.currentRouteName}' to '${routeName}' but the application instance has already been destroyed.`, !this.isDestroying && !this.isDestroyed); return this._doTransition(routeName, models, queryParams); }, @@ -387,7 +389,7 @@ const EmberRouter = EmberObject.extend(Evented, { if (DEBUG) { let infos = this._routerMicrolib.currentHandlerInfos; if (get(this, 'namespace').LOG_TRANSITIONS) { - // eslint-disable-next-line no-console + // eslint-disable-next-line no-console console.log(`Intermediate-transitioned into '${EmberRouter._routePath(infos)}'`); } } diff --git a/packages/ember-routing/tests/system/router_test.js b/packages/ember-routing/tests/system/router_test.js index 4a9bba3d12c..4aacaeb812f 100644 --- a/packages/ember-routing/tests/system/router_test.js +++ b/packages/ember-routing/tests/system/router_test.js @@ -261,5 +261,20 @@ moduleFor('Ember Router', class extends AbstractTestCase { triggerEvent(handlerInfos, false, ['loading']); } -}); + ['@test transitionTo should throw an error when called after owner is destroyed']() { + let router = createRouter(); + + runDestroy(router); + + router.currentRouteName = 'route-a'; + + expectAssertion(function() { + router.transitionTo('route-b'); + }, "A transition was attempted from 'route-a' to 'route-b' but the application instance has already been destroyed."); + + expectAssertion(function() { + router.transitionTo('./route-b/1'); + }, "A transition was attempted from 'route-a' to './route-b/1' but the application instance has already been destroyed."); + } +});