feat(router): add queryParams and fragment to every activated route
This commit is contained in:
@ -200,10 +200,11 @@ describe('createUrlTree', () => {
|
||||
|
||||
function createRoot(tree: UrlTree, commands: any[], queryParams?: Params, fragment?: string) {
|
||||
const s = new ActivatedRouteSnapshot(
|
||||
[], <any>{}, <any>{}, PRIMARY_OUTLET, 'someComponent', null, tree.root, -1, <any>null);
|
||||
[], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, tree.root, -1,
|
||||
<any>null);
|
||||
const a = new ActivatedRoute(
|
||||
new BehaviorSubject(null), new BehaviorSubject(null), new BehaviorSubject(null),
|
||||
PRIMARY_OUTLET, 'someComponent', s);
|
||||
new BehaviorSubject(null), new BehaviorSubject(null), PRIMARY_OUTLET, 'someComponent', s);
|
||||
advanceActivatedRoute(a);
|
||||
return createUrlTree(a, tree, commands, queryParams, fragment);
|
||||
}
|
||||
@ -215,11 +216,11 @@ function create(
|
||||
expect(segment).toBeDefined();
|
||||
}
|
||||
const s = new ActivatedRouteSnapshot(
|
||||
[], <any>{}, <any>{}, PRIMARY_OUTLET, 'someComponent', null, <any>segment, startIndex,
|
||||
<any>null);
|
||||
[], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, <any>segment,
|
||||
startIndex, <any>null);
|
||||
const a = new ActivatedRoute(
|
||||
new BehaviorSubject(null), new BehaviorSubject(null), new BehaviorSubject(null),
|
||||
PRIMARY_OUTLET, 'someComponent', s);
|
||||
new BehaviorSubject(null), new BehaviorSubject(null), PRIMARY_OUTLET, 'someComponent', s);
|
||||
advanceActivatedRoute(a);
|
||||
return createUrlTree(a, tree, commands, queryParams, fragment);
|
||||
}
|
@ -28,7 +28,7 @@ describe('Integration', () => {
|
||||
BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp,
|
||||
RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp,
|
||||
QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp, LinkInNgIf,
|
||||
ComponentRecordingQueryParams, ComponentRecordingRoutePathAndUrl, RouteCmp
|
||||
ComponentRecordingRoutePathAndUrl, RouteCmp
|
||||
]
|
||||
});
|
||||
});
|
||||
@ -289,29 +289,6 @@ describe('Integration', () => {
|
||||
expect(fixture.debugElement.nativeElement).toHaveText('query: 2 fragment: fragment2');
|
||||
})));
|
||||
|
||||
it('should not push query params into components that will be deactivated',
|
||||
fakeAsync(
|
||||
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
|
||||
|
||||
router.resetConfig([
|
||||
{path: '', component: ComponentRecordingQueryParams},
|
||||
{path: 'simple', component: SimpleCmp}
|
||||
]);
|
||||
|
||||
const fixture = createRoot(tcb, router, RootCmp);
|
||||
router.navigateByUrl('/?a=v1');
|
||||
advance(fixture);
|
||||
|
||||
const c = fixture.debugElement.children[1].componentInstance;
|
||||
|
||||
expect(c.recordedQueryParams).toEqual([{}, {a: 'v1'}]);
|
||||
|
||||
router.navigateByUrl('/simple?a=v2');
|
||||
advance(fixture);
|
||||
|
||||
expect(c.recordedQueryParams).toEqual([{}, {a: 'v1'}]);
|
||||
})));
|
||||
|
||||
it('should push params only when they change',
|
||||
fakeAsync(
|
||||
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
|
||||
@ -1733,18 +1710,6 @@ class DummyLinkWithParentCmp {
|
||||
constructor(route: ActivatedRoute) { this.exact = (<any>route.snapshot.params).exact === 'true'; }
|
||||
}
|
||||
|
||||
|
||||
@Component({template: ''})
|
||||
class ComponentRecordingQueryParams {
|
||||
recordedQueryParams: any[] = [];
|
||||
subscription: any;
|
||||
constructor(r: Router) {
|
||||
this.subscription = r.routerState.queryParams.subscribe(r => this.recordedQueryParams.push(r));
|
||||
}
|
||||
|
||||
ngOnDestroy() { this.subscription.unsubscribe(); }
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp', template: ''})
|
||||
class ComponentRecordingRoutePathAndUrl {
|
||||
private path: any;
|
||||
@ -1764,7 +1729,7 @@ class ComponentRecordingRoutePathAndUrl {
|
||||
BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp,
|
||||
RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp,
|
||||
QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp, LinkInNgIf,
|
||||
ComponentRecordingQueryParams, ComponentRecordingRoutePathAndUrl
|
||||
ComponentRecordingRoutePathAndUrl
|
||||
]
|
||||
})
|
||||
class RootCmp {
|
||||
|
@ -23,7 +23,7 @@ describe('RouterState & Snapshot', () => {
|
||||
|
||||
const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]);
|
||||
|
||||
state = new RouterStateSnapshot('url', root, {}, '');
|
||||
state = new RouterStateSnapshot('url', root);
|
||||
});
|
||||
|
||||
it('should return first child', () => { expect(state.root.firstChild).toBe(b); });
|
||||
@ -60,7 +60,7 @@ describe('RouterState & Snapshot', () => {
|
||||
|
||||
const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]);
|
||||
|
||||
state = new RouterState(root, <any>null, <any>null, <any>null);
|
||||
state = new RouterState(root, <any>null);
|
||||
});
|
||||
|
||||
it('should return first child', () => { expect(state.root.firstChild).toBe(b); });
|
||||
@ -87,9 +87,11 @@ describe('RouterState & Snapshot', () => {
|
||||
|
||||
function createActivatedRouteSnapshot(cmp: string) {
|
||||
return new ActivatedRouteSnapshot(
|
||||
<any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null, <any>null, -1, null);
|
||||
<any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null,
|
||||
<any>null, -1, null);
|
||||
}
|
||||
|
||||
function createActivatedRoute(cmp: string) {
|
||||
return new ActivatedRoute(<any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null);
|
||||
return new ActivatedRoute(
|
||||
<any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null);
|
||||
}
|
||||
|
Reference in New Issue
Block a user