fix(router): do not reset the router state when updating the component (#11867)
This commit is contained in:

committed by
Rado Kirov

parent
712d1a7c37
commit
cf750e17ed
@ -317,6 +317,17 @@ export class Router {
|
|||||||
this.currentRouterState = createEmptyState(this.currentUrlTree, this.rootComponentType);
|
this.currentRouterState = createEmptyState(this.currentUrlTree, this.rootComponentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* TODO: this should be removed once the constructor of the router made internal
|
||||||
|
*/
|
||||||
|
resetRootComponentType(rootComponentType: Type<any>): void {
|
||||||
|
this.rootComponentType = rootComponentType;
|
||||||
|
// TODO: vsavkin router 4.0 should make the root component set to null
|
||||||
|
// this will simplify the lifecycle of the router.
|
||||||
|
this.currentRouterState.root.component = this.rootComponentType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the location change listener and performs the initial navigation.
|
* Sets up the location change listener and performs the initial navigation.
|
||||||
*/
|
*/
|
||||||
|
@ -6,13 +6,31 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {PreActivation} from '../src/router';
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {PreActivation, Router} from '../src/router';
|
||||||
import {RouterOutletMap} from '../src/router_outlet_map';
|
import {RouterOutletMap} from '../src/router_outlet_map';
|
||||||
import {ActivatedRouteSnapshot, InheritedResolve, RouterStateSnapshot, createEmptyStateSnapshot} from '../src/router_state';
|
import {ActivatedRouteSnapshot, InheritedResolve, RouterStateSnapshot, createEmptyStateSnapshot} from '../src/router_state';
|
||||||
import {DefaultUrlSerializer} from '../src/url_tree';
|
import {DefaultUrlSerializer} from '../src/url_tree';
|
||||||
import {TreeNode} from '../src/utils/tree';
|
import {TreeNode} from '../src/utils/tree';
|
||||||
|
import {RouterTestingModule} from '../testing/router_testing_module';
|
||||||
|
|
||||||
describe('Router', () => {
|
describe('Router', () => {
|
||||||
|
describe('resetRootComponentType', () => {
|
||||||
|
class NewRootComponent {}
|
||||||
|
|
||||||
|
beforeEach(() => { TestBed.configureTestingModule({imports: [RouterTestingModule]}); });
|
||||||
|
|
||||||
|
it('should not change root route when updating the root component', () => {
|
||||||
|
const r: Router = TestBed.get(Router);
|
||||||
|
const root = r.routerState.root;
|
||||||
|
|
||||||
|
r.resetRootComponentType(NewRootComponent);
|
||||||
|
|
||||||
|
expect(r.routerState.root).toBe(root);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('PreActivation', () => {
|
describe('PreActivation', () => {
|
||||||
const serializer = new DefaultUrlSerializer();
|
const serializer = new DefaultUrlSerializer();
|
||||||
const inj = {get: (token: any) => () => `${token}_value`};
|
const inj = {get: (token: any) => () => `${token}_value`};
|
||||||
|
Reference in New Issue
Block a user