fix(router): call data observers when the path changes
This commit is contained in:
parent
a178bc6c83
commit
1de04b23b1
|
@ -435,11 +435,13 @@ export function advanceActivatedRoute(route: ActivatedRoute): void {
|
||||||
}
|
}
|
||||||
if (!shallowEqual(route.snapshot.params, route._futureSnapshot.params)) {
|
if (!shallowEqual(route.snapshot.params, route._futureSnapshot.params)) {
|
||||||
(<any>route.params).next(route._futureSnapshot.params);
|
(<any>route.params).next(route._futureSnapshot.params);
|
||||||
(<any>route.data).next(route._futureSnapshot.data);
|
|
||||||
}
|
}
|
||||||
if (!shallowEqualArrays(route.snapshot.url, route._futureSnapshot.url)) {
|
if (!shallowEqualArrays(route.snapshot.url, route._futureSnapshot.url)) {
|
||||||
(<any>route.url).next(route._futureSnapshot.url);
|
(<any>route.url).next(route._futureSnapshot.url);
|
||||||
}
|
}
|
||||||
|
if (!equalParamsAndUrlSegments(route.snapshot, route._futureSnapshot)) {
|
||||||
|
(<any>route.data).next(route._futureSnapshot.data);
|
||||||
|
}
|
||||||
route.snapshot = route._futureSnapshot;
|
route.snapshot = route._futureSnapshot;
|
||||||
} else {
|
} else {
|
||||||
route.snapshot = route._futureSnapshot;
|
route.snapshot = route._futureSnapshot;
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {Params} from '../src/shared';
|
||||||
import {UrlSegment} from '../src/url_tree';
|
import {UrlSegment} from '../src/url_tree';
|
||||||
import {TreeNode} from '../src/utils/tree';
|
import {TreeNode} from '../src/utils/tree';
|
||||||
|
@ -122,6 +124,34 @@ describe('RouterState & Snapshot', () => {
|
||||||
.toEqual(true);
|
.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, <any>null, <any>null, <any>null, <any>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) {
|
function createActivatedRouteSnapshot(cmp: string) {
|
||||||
|
@ -132,5 +162,6 @@ function createActivatedRouteSnapshot(cmp: string) {
|
||||||
|
|
||||||
function createActivatedRoute(cmp: string) {
|
function createActivatedRoute(cmp: string) {
|
||||||
return new ActivatedRoute(
|
return new ActivatedRoute(
|
||||||
<any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null);
|
new BehaviorSubject([new UrlSegment('', {})]), new BehaviorSubject({}), <any>null, <any>null,
|
||||||
|
new BehaviorSubject({}), <any>null, <any>cmp, <any>null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue