Skip to content

Commit b854a9b

Browse files
author
FrancescoMauto
committed
[DSC-2400] fix redirect for item page resolver
Porting of [CST-24936]
1 parent 2b970e1 commit b854a9b

3 files changed

Lines changed: 2165 additions & 2962 deletions

File tree

src/app/core/shared/authorized.operators.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ export const redirectOn4xx = <T>(router: Router, authService: AuthService) =>
3333
router.navigateByUrl(getForbiddenRoute(), { skipLocationChange: true });
3434
return false;
3535
} else {
36-
authService.setRedirectUrl(router.url);
37-
router.navigateByUrl('login');
36+
// During a resolver the navigation hasn't committed yet, so router.url still
37+
// points to the previous URL (e.g. '/'). Use the in-flight navigation's URL
38+
// when available, falling back to router.url for component-level calls.
39+
const redirectUrl = router.getCurrentNavigation()?.extractedUrl?.toString() ?? router.url;
40+
authService.setRedirectUrl(redirectUrl, 'login');
3841
return false;
3942
}
4043
}

src/app/core/shared/operators.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe('Core Module - RxJS Operators', () => {
180180
testScheduler = new TestScheduler((actual, expected) => {
181181
expect(actual).toEqual(expected);
182182
});
183-
router = jasmine.createSpyObj('router', ['navigateByUrl']);
183+
router = jasmine.createSpyObj('router', ['navigateByUrl', 'getCurrentNavigation']);
184184
authService = jasmine.createSpyObj('authService', {
185185
isAuthenticated: observableOf(true),
186186
setRedirectUrl: {}

0 commit comments

Comments
 (0)