Skip to content

Commit 397dbc4

Browse files
atscottkirjs
authored andcommitted
Revert "refactor(router): Retain original navigateEvent across redirects"
This reverts commit 53d3ae0.
1 parent b17f93b commit 397dbc4

2 files changed

Lines changed: 3 additions & 35 deletions

File tree

packages/router/src/statemanager/navigation_state_manager.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,8 @@ export class NavigationStateManager extends StateManager {
199199
resolve();
200200
});
201201
} else if (e instanceof NavigationCancel || e instanceof NavigationError) {
202-
// If redirecting and the URL hasn't been committed yet (via precommmitHandler),
203-
// the redirect will be handled by `commitUrl` using `controller.redirect` and
204-
// we should retain the current NavigateEvent.
205-
// Otherwise, a full cancellation and rollback is needed.
206-
const redirectingBeforeUrlCommit =
207-
e instanceof NavigationCancel &&
208-
e.code === NavigationCancellationCode.Redirect &&
209-
!!this.currentNavigation.commitUrl;
210-
if (redirectingBeforeUrlCommit) {
211-
return;
212-
}
202+
// TODO(atscott): We want to keep the navigation event on redirects if
203+
// the URL wasn't committed yet rather than cancelling it.
213204
void this.cancel(transition, e);
214205
} else if (e instanceof NavigationEnd) {
215206
const {resolveHandler, removeAbortListener} = this.currentNavigation;

packages/router/test/with_platform_navigation.spec.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@
77
*/
88

99
import {TestBed} from '@angular/core/testing';
10-
import {NavigationEnd, NavigationStart, provideRouter, Router} from '../src';
10+
import {provideRouter, Router} from '../src';
1111
import {withPlatformNavigation, withRouterConfig} from '../src/provide_router';
1212
import {withBody} from '@angular/private/testing';
1313
import {
1414
PlatformLocation,
1515
Location,
1616
PlatformNavigation,
1717
BrowserPlatformLocation,
18-
ɵPRECOMMIT_HANDLER_SUPPORTED as PRECOMMIT_HANDLER_SUPPORTED,
1918
} from '@angular/common';
2019
import {
2120
ɵFakeNavigation as FakeNavigation,
2221
ɵFakeNavigationPlatformLocation as FakeNavigationPlatformLocation,
2322
provideLocationMocks,
2423
} from '@angular/common/testing';
2524
import {timeout, useAutoTick} from './helpers';
26-
import {} from '../../common/src/navigation/platform_navigation';
27-
import {inject} from '@angular/core';
2825

2926
/// <reference types="dom-navigation" />
3027

@@ -160,26 +157,6 @@ describe('withPlatformNavigation feature', () => {
160157
expect(navigateEvents.length).toBe(1);
161158
expect(navigateEvents[0].navigationType).toBe('traverse');
162159
});
163-
164-
it('retains a single NavigateEvent across redirects', async () => {
165-
const navigateEvents: NavigateEvent[] = [];
166-
navigation.addEventListener('navigate', (e: NavigateEvent) => navigateEvents.push(e));
167-
168-
router.resetConfig([
169-
{path: 'first', canActivate: [() => inject(Router).parseUrl('/redirected')], children: []},
170-
{path: '**', children: []},
171-
]);
172-
const navPromise = router.navigateByUrl('/first');
173-
if (TestBed.inject(PRECOMMIT_HANDLER_SUPPORTED)) {
174-
router.events.subscribe((e) => {
175-
if (e instanceof NavigationStart) {
176-
expect(navigateEvents.length).toBe(1);
177-
}
178-
});
179-
}
180-
await navPromise;
181-
expect(navigateEvents.length).toBe(1);
182-
});
183160
});
184161

185162
describe('eager url update', () => {

0 commit comments

Comments
 (0)