diff --git a/package.json b/package.json index 774512b78f9..405f56553e0 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "rollup-plugin-commonjs": "^9.3.4", "rollup-plugin-node-resolve": "^4.2.4", "route-recognizer": "^0.3.4", - "router_js": "^7.2.0", + "router_js": "^7.3.0", "rsvp": "^4.8.5", "serve-static": "^1.14.1", "simple-dom": "^1.4.0", diff --git a/packages/@ember/-internals/routing/lib/system/router.ts b/packages/@ember/-internals/routing/lib/system/router.ts index 1fa016d866a..a31c86797cd 100644 --- a/packages/@ember/-internals/routing/lib/system/router.ts +++ b/packages/@ember/-internals/routing/lib/system/router.ts @@ -286,6 +286,12 @@ class EmberRouter extends EmberObject { routeWillChange(transition: Transition) { router.trigger('routeWillChange', transition); + // in case of intermediate transition we update the current route + // to make router.currentRoute.name consistent with router.currentRouteName + // see https://github.com/emberjs/ember.js/issues/19449 + if (transition.isIntermediate) { + router.set('currentRoute', transition.to); + } } routeDidChange(transition: Transition) { diff --git a/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js b/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js index dcba7155853..36fb5c2598f 100644 --- a/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js +++ b/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js @@ -17,7 +17,7 @@ let InstrumentedRoute = Route.extend({ let service = get(this, 'routerService'); service.on('routeWillChange', (transition) => { results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} routeWillChange: ${transition.from && transition.from.name} - ${ transition.to.name }`, @@ -26,7 +26,7 @@ let InstrumentedRoute = Route.extend({ }); service.on('routeDidChange', (transition) => { results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} routeDidChange: ${transition.from && transition.from.name} - ${ transition.to.name }`, @@ -38,7 +38,7 @@ let InstrumentedRoute = Route.extend({ activate() { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} activate`, service.get('currentURL'), ]); @@ -47,7 +47,7 @@ let InstrumentedRoute = Route.extend({ redirect() { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} redirect`, service.get('currentURL'), ]); @@ -56,7 +56,7 @@ let InstrumentedRoute = Route.extend({ beforeModel() { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} beforeModel`, service.get('currentURL'), ]); @@ -65,7 +65,7 @@ let InstrumentedRoute = Route.extend({ model() { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} model`, service.get('currentURL'), ]); @@ -77,7 +77,7 @@ let InstrumentedRoute = Route.extend({ afterModel() { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} afterModel`, service.get('currentURL'), ]); @@ -87,7 +87,7 @@ let InstrumentedRoute = Route.extend({ willTransition(transition) { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} willTransition: ${transition.from && transition.from.name} - ${ transition.to.name }`, @@ -98,7 +98,7 @@ let InstrumentedRoute = Route.extend({ didTransition() { let service = get(this, 'routerService'); results.push([ - service.get('currentRouteName'), + `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, `${this.routeName} didTransition`, service.get('currentURL'), ]); @@ -108,7 +108,7 @@ let InstrumentedRoute = Route.extend({ }); moduleFor( - 'Router Service - currentURL | currentRouteName', + 'Router Service - currentURL | currentRouteName | currentRoute.name', class extends RouterTestCase { constructor() { super(...arguments); @@ -189,18 +189,26 @@ moduleFor( return this.visit('/') .then(() => { assert.deepEqual(results, [ - [null, 'parent.index routeWillChange: null - parent.index', null], - [null, 'parent.index beforeModel', null], - [null, 'parent.index model', null], - [null, 'parent.loading activate', null], - [null, 'parent.loading routeWillChange: null - parent.loading', null], - [null, 'parent.index routeWillChange: null - parent.loading', null], - ['parent.loading', 'parent.index afterModel', '/'], - ['parent.loading', 'parent.index redirect', '/'], - ['parent.loading', 'parent.index activate', '/'], - ['parent.loading', 'parent.index didTransition', '/'], - ['parent.index', 'parent.loading routeDidChange: null - parent.index', '/'], - ['parent.index', 'parent.index routeDidChange: null - parent.index', '/'], + ['null - undefined', 'parent.index routeWillChange: null - parent.index', null], + ['null - undefined', 'parent.index beforeModel', null], + ['null - undefined', 'parent.index model', null], + ['null - undefined', 'parent.loading activate', null], + ['null - undefined', 'parent.loading routeWillChange: null - parent.loading', null], + ['null - undefined', 'parent.index routeWillChange: null - parent.loading', null], + ['parent.loading - parent.loading', 'parent.index afterModel', '/'], + ['parent.loading - parent.loading', 'parent.index redirect', '/'], + ['parent.loading - parent.loading', 'parent.index activate', '/'], + ['parent.loading - parent.loading', 'parent.index didTransition', '/'], + [ + 'parent.index - parent.index', + 'parent.loading routeDidChange: null - parent.index', + '/', + ], + [ + 'parent.index - parent.index', + 'parent.index routeDidChange: null - parent.index', + '/', + ], ]); results = []; @@ -209,27 +217,63 @@ moduleFor( }) .then(() => { assert.deepEqual(results, [ - ['parent.index', 'parent.index willTransition: parent.index - parent.child', '/'], - ['parent.index', 'parent.child routeWillChange: parent.index - parent.child', '/'], - ['parent.index', 'parent.loading routeWillChange: parent.index - parent.child', '/'], - ['parent.index', 'parent.index routeWillChange: parent.index - parent.child', '/'], - ['parent.index', 'parent.child beforeModel', '/'], - ['parent.index', 'parent.child model', '/'], - ['parent.index', 'parent.loading activate', '/'], - ['parent.index', 'parent.child routeWillChange: parent.index - parent.loading', '/'], - ['parent.index', 'parent.loading routeWillChange: parent.index - parent.loading', '/'], - ['parent.index', 'parent.index routeWillChange: parent.index - parent.loading', '/'], - ['parent.loading', 'parent.child afterModel', '/child'], - ['parent.loading', 'parent.child redirect', '/child'], - ['parent.loading', 'parent.child activate', '/child'], - ['parent.loading', 'parent.child didTransition', '/child'], - ['parent.child', 'parent.child routeDidChange: parent.index - parent.child', '/child'], [ - 'parent.child', + 'parent.index - parent.index', + 'parent.index willTransition: parent.index - parent.child', + '/', + ], + [ + 'parent.index - parent.index', + 'parent.child routeWillChange: parent.index - parent.child', + '/', + ], + [ + 'parent.index - parent.index', + 'parent.loading routeWillChange: parent.index - parent.child', + '/', + ], + [ + 'parent.index - parent.index', + 'parent.index routeWillChange: parent.index - parent.child', + '/', + ], + ['parent.index - parent.index', 'parent.child beforeModel', '/'], + ['parent.index - parent.index', 'parent.child model', '/'], + ['parent.index - parent.index', 'parent.loading activate', '/'], + [ + 'parent.index - parent.index', + 'parent.child routeWillChange: parent.index - parent.loading', + '/', + ], + [ + 'parent.index - parent.index', + 'parent.loading routeWillChange: parent.index - parent.loading', + '/', + ], + [ + 'parent.index - parent.index', + 'parent.index routeWillChange: parent.index - parent.loading', + '/', + ], + ['parent.loading - parent.loading', 'parent.child afterModel', '/child'], + ['parent.loading - parent.loading', 'parent.child redirect', '/child'], + ['parent.loading - parent.loading', 'parent.child activate', '/child'], + ['parent.loading - parent.loading', 'parent.child didTransition', '/child'], + [ + 'parent.child - parent.child', + 'parent.child routeDidChange: parent.index - parent.child', + '/child', + ], + [ + 'parent.child - parent.child', 'parent.loading routeDidChange: parent.index - parent.child', '/child', ], - ['parent.child', 'parent.index routeDidChange: parent.index - parent.child', '/child'], + [ + 'parent.child - parent.child', + 'parent.index routeDidChange: parent.index - parent.child', + '/child', + ], ]); }); } diff --git a/yarn.lock b/yarn.lock index f9928a93155..57650be1ab2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8907,10 +8907,10 @@ route-recognizer@^0.3.4: resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3" integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g== -router_js@^7.2.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/router_js/-/router_js-7.2.0.tgz#a7168155fe494f85f1e5058802a3a633c29ea243" - integrity sha512-kZBOqD/kRMDymmVbiVrX6OK3cGBoG1c9tO8egxkoxX2TgC78sBwFhvFqkAJLvK8oTEXYNcjk8+FbNIn9hg9VMA== +router_js@^7.3.0: + version "7.3.0" + resolved "https://registry.yarnpkg.com/router_js/-/router_js-7.3.0.tgz#6c061b6b097cfec537fa0d6c5a5c6e317730799f" + integrity sha512-A+iVTfG03XNks7oC/KGXq+EKp9kAac9BOYuomq2KouXUM4U57Io20/tuQq1kx+OwHB4gEY0XaRQjuHwljkbRHg== dependencies: "@glimmer/env" "^0.1.7"