fix(router): should navigate to the same url when config changes
Closes #15535
This commit is contained in:
parent
ad3029e786
commit
eb6fb5f87e
|
@ -313,7 +313,7 @@ export class Router {
|
|||
get events(): Observable<Event> { return this.routerEvents; }
|
||||
|
||||
/** @internal */
|
||||
triggerEvent(e: Event) { this.routerEvents.next(e); }
|
||||
triggerEvent(e: Event): void { this.routerEvents.next(e); }
|
||||
|
||||
/**
|
||||
* Resets the configuration used for navigation and generating links.
|
||||
|
@ -332,10 +332,11 @@ export class Router {
|
|||
resetConfig(config: Routes): void {
|
||||
validateConfig(config);
|
||||
this.config = config;
|
||||
this.navigated = false;
|
||||
}
|
||||
|
||||
/** @docsNotRequired */
|
||||
ngOnDestroy() { this.dispose(); }
|
||||
ngOnDestroy(): void { this.dispose(); }
|
||||
|
||||
/** Disposes of the router */
|
||||
dispose(): void {
|
||||
|
|
|
@ -398,6 +398,25 @@ describe('Integration', () => {
|
|||
expect(location.path()).toEqual('/team/22/user/victor');
|
||||
})));
|
||||
|
||||
it('should navigate to the same url when config changes',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
||||
router.resetConfig([{path: 'a', component: SimpleCmp}]);
|
||||
|
||||
router.navigate(['/a']);
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/a');
|
||||
expect(fixture.nativeElement).toHaveText('simple');
|
||||
|
||||
router.resetConfig([{path: 'a', component: RouteCmp}]);
|
||||
|
||||
router.navigate(['/a']);
|
||||
advance(fixture);
|
||||
expect(location.path()).toEqual('/a');
|
||||
expect(fixture.nativeElement).toHaveText('route');
|
||||
})));
|
||||
|
||||
it('should navigate when locations changes',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
|
Loading…
Reference in New Issue