fix(router): update URL after redirects when urlHandlingStrategy='eager' (#27356)
fixes #27076 PR Close #27356
This commit is contained in:
parent
57dae161c3
commit
11a8bd8aca
|
@ -389,9 +389,6 @@ export class Router {
|
||||||
|
|
||||||
if (processCurrentUrl) {
|
if (processCurrentUrl) {
|
||||||
return of (t).pipe(
|
return of (t).pipe(
|
||||||
// Update URL if in `eager` update mode
|
|
||||||
tap(t => this.urlUpdateStrategy === 'eager' && !t.extras.skipLocationChange &&
|
|
||||||
this.setBrowserUrl(t.rawUrl, !!t.extras.replaceUrl, t.id)),
|
|
||||||
// Fire NavigationStart event
|
// Fire NavigationStart event
|
||||||
switchMap(t => {
|
switchMap(t => {
|
||||||
const transition = this.transitions.getValue();
|
const transition = this.transitions.getValue();
|
||||||
|
@ -416,6 +413,10 @@ export class Router {
|
||||||
this.rootComponentType, this.config, (url) => this.serializeUrl(url),
|
this.rootComponentType, this.config, (url) => this.serializeUrl(url),
|
||||||
this.paramsInheritanceStrategy, this.relativeLinkResolution),
|
this.paramsInheritanceStrategy, this.relativeLinkResolution),
|
||||||
|
|
||||||
|
// Update URL if in `eager` update mode
|
||||||
|
tap(t => this.urlUpdateStrategy === 'eager' && !t.extras.skipLocationChange &&
|
||||||
|
this.setBrowserUrl(t.urlAfterRedirects, !!t.extras.replaceUrl, t.id)),
|
||||||
|
|
||||||
// Fire RoutesRecognized
|
// Fire RoutesRecognized
|
||||||
tap(t => {
|
tap(t => {
|
||||||
const routesRecognized = new RoutesRecognized(
|
const routesRecognized = new RoutesRecognized(
|
||||||
|
|
|
@ -578,6 +578,41 @@ describe('Integration', () => {
|
||||||
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
fixmeIvy('FW-???: Error: ExpressionChangedAfterItHasBeenCheckedError') &&
|
||||||
|
it('should eagerly update URL after redirects are applied with urlUpdateStrategy="eagar"',
|
||||||
|
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||||
|
const fixture = TestBed.createComponent(RootCmp);
|
||||||
|
advance(fixture);
|
||||||
|
|
||||||
|
router.resetConfig([{path: 'team/:id', component: TeamCmp}]);
|
||||||
|
|
||||||
|
router.navigateByUrl('/team/22');
|
||||||
|
advance(fixture);
|
||||||
|
expect(location.path()).toEqual('/team/22');
|
||||||
|
|
||||||
|
expect(fixture.nativeElement).toHaveText('team 22 [ , right: ]');
|
||||||
|
|
||||||
|
router.urlUpdateStrategy = 'eager';
|
||||||
|
|
||||||
|
let urlAtNavStart = '';
|
||||||
|
let urlAtRoutesRecognized = '';
|
||||||
|
router.events.subscribe(e => {
|
||||||
|
if (e instanceof NavigationStart) {
|
||||||
|
urlAtNavStart = location.path();
|
||||||
|
}
|
||||||
|
if (e instanceof RoutesRecognized) {
|
||||||
|
urlAtRoutesRecognized = location.path();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.navigateByUrl('/team/33');
|
||||||
|
|
||||||
|
advance(fixture);
|
||||||
|
expect(urlAtNavStart).toBe('/team/22');
|
||||||
|
expect(urlAtRoutesRecognized).toBe('/team/33');
|
||||||
|
expect(fixture.nativeElement).toHaveText('team 33 [ , right: ]');
|
||||||
|
})));
|
||||||
|
|
||||||
fixmeIvy('FW-???: Error: ExpressionChangedAfterItHasBeenCheckedError') &&
|
fixmeIvy('FW-???: Error: ExpressionChangedAfterItHasBeenCheckedError') &&
|
||||||
it('should navigate back and forward',
|
it('should navigate back and forward',
|
||||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||||
|
|
Loading…
Reference in New Issue