fix(router): advance query params and fragment after advanced routes
This commit is contained in:
parent
43437c175a
commit
06e4ca4bb3
@ -644,9 +644,9 @@ class ActivateRoutes {
|
|||||||
activate(parentOutletMap: RouterOutletMap): void {
|
activate(parentOutletMap: RouterOutletMap): void {
|
||||||
const futureRoot = this.futureState._root;
|
const futureRoot = this.futureState._root;
|
||||||
const currRoot = this.currState ? this.currState._root : null;
|
const currRoot = this.currState ? this.currState._root : null;
|
||||||
pushQueryParamsAndFragment(this.futureState);
|
|
||||||
advanceActivatedRoute(this.futureState.root);
|
advanceActivatedRoute(this.futureState.root);
|
||||||
this.activateChildRoutes(futureRoot, currRoot, parentOutletMap);
|
this.activateChildRoutes(futureRoot, currRoot, parentOutletMap);
|
||||||
|
pushQueryParamsAndFragment(this.futureState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private activateChildRoutes(
|
private activateChildRoutes(
|
||||||
|
@ -251,6 +251,47 @@ describe('Integration', () => {
|
|||||||
expect(fixture.debugElement.nativeElement).toHaveText('query: 2 fragment: fragment2');
|
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) => {
|
||||||
|
@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({
|
||||||
|
template: '<router-outlet></router-outlet>',
|
||||||
|
precompile: [SimpleCmp, ComponentRecordingQueryParams]
|
||||||
|
})
|
||||||
|
class RootCmp {
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
it('should push params only when they change',
|
||||||
fakeAsync(
|
fakeAsync(
|
||||||
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
|
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user