Skip to content

Commit 4e7d07b

Browse files
author
FrancescoMauto
committed
[DURACOM-496] fix redirect for item page resolver
Porting of [CST-24936]
1 parent d929c2c commit 4e7d07b

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ export const redirectOn4xx = <T>(router: Router, authService: AuthService) =>
4646
router.navigateByUrl(getForbiddenRoute(), { skipLocationChange: true });
4747
return false;
4848
} else {
49-
authService.setRedirectUrl(router.url);
50-
router.navigateByUrl('login');
49+
// During a resolver the navigation hasn't committed yet, so router.url still
50+
// points to the previous URL (e.g. '/'). Use the in-flight navigation's URL
51+
// when available, falling back to router.url for component-level calls.
52+
const redirectUrl = router.getCurrentNavigation()?.extractedUrl?.toString() ?? router.url;
53+
authService.setRedirectUrl(redirectUrl, 'login');
5154
return false;
5255
}
5356
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('Core Module - RxJS Operators', () => {
190190
testScheduler = new TestScheduler((actual, expected) => {
191191
expect(actual).toEqual(expected);
192192
});
193-
router = jasmine.createSpyObj('router', ['navigateByUrl']);
193+
router = jasmine.createSpyObj('router', ['navigateByUrl', 'getCurrentNavigation']);
194194
authService = jasmine.createSpyObj('authService', {
195195
isAuthenticated: of(true),
196196
setRedirectUrl: {},

0 commit comments

Comments
 (0)