fix(router): advance query params and fragment after advanced routes

This commit is contained in:
vsavkin 2016-07-22 17:14:04 -07:00
parent 43437c175a
commit 06e4ca4bb3
2 changed files with 42 additions and 1 deletions

View File

@ -644,9 +644,9 @@ class ActivateRoutes {
activate(parentOutletMap: RouterOutletMap): void {
const futureRoot = this.futureState._root;
const currRoot = this.currState ? this.currState._root : null;
pushQueryParamsAndFragment(this.futureState);
advanceActivatedRoute(this.futureState.root);
this.activateChildRoutes(futureRoot, currRoot, parentOutletMap);
pushQueryParamsAndFragment(this.futureState);
}
private activateChildRoutes(

View File

@ -251,6 +251,47 @@ 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) => {
@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',
fakeAsync(
inject([Router, TestComponentBuilder], (router: Router, tcb: TestComponentBuilder) => {