fix(router): update the location before activating components
This commit is contained in:
parent
b9647b7347
commit
2ffecc0e14
|
@ -500,8 +500,6 @@ export class Router {
|
||||||
this.currentUrlTree = appliedUrl;
|
this.currentUrlTree = appliedUrl;
|
||||||
this.currentRouterState = state;
|
this.currentRouterState = state;
|
||||||
|
|
||||||
new ActivateRoutes(state, storedState).activate(this.outletMap);
|
|
||||||
|
|
||||||
if (!shouldPreventPushState) {
|
if (!shouldPreventPushState) {
|
||||||
let path = this.urlSerializer.serialize(appliedUrl);
|
let path = this.urlSerializer.serialize(appliedUrl);
|
||||||
if (this.location.isCurrentPathEqualTo(path) || shouldReplaceUrl) {
|
if (this.location.isCurrentPathEqualTo(path) || shouldReplaceUrl) {
|
||||||
|
@ -510,6 +508,9 @@ export class Router {
|
||||||
this.location.go(path);
|
this.location.go(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new ActivateRoutes(state, storedState).activate(this.outletMap);
|
||||||
|
|
||||||
navigationIsSuccessful = true;
|
navigationIsSuccessful = true;
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
|
@ -536,6 +537,7 @@ export class Router {
|
||||||
}
|
}
|
||||||
this.currentRouterState = storedState;
|
this.currentRouterState = storedState;
|
||||||
this.currentUrlTree = storedUrl;
|
this.currentUrlTree = storedUrl;
|
||||||
|
this.location.replaceState(this.serializeUrl(storedUrl));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,21 +89,36 @@ describe('Integration', () => {
|
||||||
expect(recordedError.message).toEqual('Cannot find primary outlet to load \'BlankCmp\'');
|
expect(recordedError.message).toEqual('Cannot find primary outlet to load \'BlankCmp\'');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should update location when navigating',
|
it('should update location when navigating', fakeAsync(() => {
|
||||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
@Component({template: `record`})
|
||||||
|
class RecordLocationCmp {
|
||||||
|
private storedPath: string;
|
||||||
|
constructor(loc: Location) { this.storedPath = loc.path(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@NgModule({declarations: [RecordLocationCmp], entryComponents: [RecordLocationCmp]})
|
||||||
|
class TestModule {
|
||||||
|
}
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({imports: [TestModule]});
|
||||||
|
|
||||||
|
const router = TestBed.get(Router);
|
||||||
|
const location = TestBed.get(Location);
|
||||||
const fixture = createRoot(router, RootCmp);
|
const fixture = createRoot(router, RootCmp);
|
||||||
|
|
||||||
router.resetConfig([{path: 'team/:id', component: TeamCmp}]);
|
router.resetConfig([{path: 'record/:id', component: RecordLocationCmp}]);
|
||||||
|
|
||||||
router.navigateByUrl('/team/22');
|
router.navigateByUrl('/record/22');
|
||||||
advance(fixture);
|
|
||||||
expect(location.path()).toEqual('/team/22');
|
|
||||||
|
|
||||||
router.navigateByUrl('/team/33');
|
|
||||||
advance(fixture);
|
advance(fixture);
|
||||||
|
|
||||||
expect(location.path()).toEqual('/team/33');
|
const c = fixture.debugElement.children[1].componentInstance;
|
||||||
})));
|
expect(location.path()).toEqual('/record/22');
|
||||||
|
expect(c.storedPath).toEqual('/record/22');
|
||||||
|
|
||||||
|
router.navigateByUrl('/record/33');
|
||||||
|
advance(fixture);
|
||||||
|
expect(location.path()).toEqual('/record/33');
|
||||||
|
}));
|
||||||
|
|
||||||
it('should skip location update when using NavigationExtras.skipLocationChange with navigateByUrl',
|
it('should skip location update when using NavigationExtras.skipLocationChange with navigateByUrl',
|
||||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||||
|
|
Loading…
Reference in New Issue