@@ -4,10 +4,11 @@ import {
44CanActivateFn ,
55Router ,
66RouterStateSnapshot ,
7+ UrlTree ,
78} from '@angular/router' ;
89import { HttpErrorResponse } from '@angular/common/http' ;
910import { Observable , of } from 'rxjs' ;
10- import { filter , take , tap } from 'rxjs/operators' ;
11+ import { map , take } from 'rxjs/operators' ;
1112import { AuthService , IAbpGuard } from '../abstracts' ;
1213import { findRoute , getRoutePath } from '../utils/route-utils' ;
1314import { RoutesService , PermissionService , HttpErrorReporterService } from '../services' ;
@@ -25,7 +26,7 @@ export class PermissionGuard implements IAbpGuard {
2526protected readonly permissionService = inject ( PermissionService ) ;
2627protected readonly httpErrorReporter = inject ( HttpErrorReporterService ) ;
2728
28- canActivate ( route :ActivatedRouteSnapshot , state :RouterStateSnapshot ) :Observable < boolean > {
29+ canActivate ( route :ActivatedRouteSnapshot , state :RouterStateSnapshot ) :Observable < boolean | UrlTree > {
2930let { requiredPolicy} = route . data || { } ;
3031
3132if ( ! requiredPolicy ) {
@@ -38,12 +39,19 @@ export class PermissionGuard implements IAbpGuard {
3839}
3940
4041return this . permissionService . getGrantedPolicy$ ( requiredPolicy ) . pipe (
41- filter ( Boolean ) ,
4242take ( 1 ) ,
43- tap ( access => {
44- if ( ! access && this . authService . isAuthenticated ) {
43+ map ( access => {
44+ if ( access ) return true ;
45+
46+ if ( route . data ?. [ 'redirectUrl' ] ) {
47+ return this . router . parseUrl ( route . data [ 'redirectUrl' ] ) ;
48+ }
49+
50+ if ( this . authService . isAuthenticated ) {
4551this . httpErrorReporter . reportError ( { status :403 } as HttpErrorResponse ) ;
4652}
53+
54+ return false ;
4755} ) ,
4856) ;
4957}
@@ -77,12 +85,19 @@ export const permissionGuard: CanActivateFn = (
7785}
7886
7987return permissionService . getGrantedPolicy$ ( requiredPolicy ) . pipe (
80- filter ( Boolean ) ,
8188take ( 1 ) ,
82- tap ( access => {
83- if ( ! access && authService . isAuthenticated ) {
89+ map ( access => {
90+ if ( access ) return true ;
91+
92+ if ( route . data ?. [ 'redirectUrl' ] ) {
93+ return router . parseUrl ( route . data [ 'redirectUrl' ] ) ;
94+ }
95+
96+ if ( authService . isAuthenticated ) {
8497httpErrorReporter . reportError ( { status :403 } as HttpErrorResponse ) ;
8598}
99+
100+ return false ;
86101} ) ,
87102) ;
88103} ;