diff --git a/modules/@angular/router/src/router_state.ts b/modules/@angular/router/src/router_state.ts index 832c1fc0f9..929535d71d 100644 --- a/modules/@angular/router/src/router_state.ts +++ b/modules/@angular/router/src/router_state.ts @@ -435,11 +435,13 @@ export function advanceActivatedRoute(route: ActivatedRoute): void { } if (!shallowEqual(route.snapshot.params, route._futureSnapshot.params)) { (route.params).next(route._futureSnapshot.params); - (route.data).next(route._futureSnapshot.data); } if (!shallowEqualArrays(route.snapshot.url, route._futureSnapshot.url)) { (route.url).next(route._futureSnapshot.url); } + if (!equalParamsAndUrlSegments(route.snapshot, route._futureSnapshot)) { + (route.data).next(route._futureSnapshot.data); + } route.snapshot = route._futureSnapshot; } else { route.snapshot = route._futureSnapshot; diff --git a/modules/@angular/router/test/router_state.spec.ts b/modules/@angular/router/test/router_state.spec.ts index ec9677c2fd..1076629b02 100644 --- a/modules/@angular/router/test/router_state.spec.ts +++ b/modules/@angular/router/test/router_state.spec.ts @@ -6,7 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, equalParamsAndUrlSegments} from '../src/router_state'; +import {BehaviorSubject} from 'rxjs/BehaviorSubject'; + +import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, equalParamsAndUrlSegments} from '../src/router_state'; import {Params} from '../src/shared'; import {UrlSegment} from '../src/url_tree'; import {TreeNode} from '../src/utils/tree'; @@ -122,6 +124,34 @@ describe('RouterState & Snapshot', () => { .toEqual(true); }); }); + + describe('advanceActivatedRoute', () => { + + let route: ActivatedRoute; + + beforeEach(() => { route = createActivatedRoute('a'); }); + + function createSnapshot(params: Params, url: UrlSegment[]): ActivatedRouteSnapshot { + const queryParams = {}; + const fragment = ''; + const data = {}; + return new ActivatedRouteSnapshot( + url, params, queryParams, fragment, data, null, null, null, null, -1, + null); + } + + it('should call change observers', () => { + const firstPlace = createSnapshot({a: 1}, []); + const secondPlace = createSnapshot({a: 2}, []); + route.snapshot = firstPlace; + route._futureSnapshot = secondPlace; + + let hasSeenDataChange = false; + route.data.forEach((data) => { hasSeenDataChange = true; }); + advanceActivatedRoute(route); + expect(hasSeenDataChange).toEqual(true); + }); + }); }); function createActivatedRouteSnapshot(cmp: string) { @@ -132,5 +162,6 @@ function createActivatedRouteSnapshot(cmp: string) { function createActivatedRoute(cmp: string) { return new ActivatedRoute( - null, null, null, null, null, null, cmp, null); + new BehaviorSubject([new UrlSegment('', {})]), new BehaviorSubject({}), null, null, + new BehaviorSubject({}), null, cmp, null); }