mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2904] Search - redirect breaks application (#3268)
* set navigation commands over plain string * fix test * lint
This commit is contained in:
committed by
Eugenio Romano
parent
c90ad3f875
commit
d456b3cba1
@@ -16,7 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, Router } from '@angular/router';
|
||||
import {
|
||||
ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, Router,
|
||||
PRIMARY_OUTLET, UrlTree, UrlSegmentGroup, UrlSegment
|
||||
} from '@angular/router';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
@@ -50,10 +53,11 @@ export class AuthGuardEcm implements CanActivate {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
||||
|
||||
return this.isLoggedIn().then(isLoggedIn => {
|
||||
if (!isLoggedIn) {
|
||||
this.authService.setRedirectUrl({ provider: 'ECM', url: state.url });
|
||||
const navigation = this.getNavigationCommands(state.url);
|
||||
|
||||
this.authService.setRedirect({ provider: 'ECM', navigation });
|
||||
const pathToLogin = this.getRouteDestinationForLogin();
|
||||
this.router.navigate(['/' + pathToLogin]);
|
||||
}
|
||||
@@ -67,4 +71,15 @@ export class AuthGuardEcm implements CanActivate {
|
||||
this.appConfig.get<string>('loginRoute') ?
|
||||
this.appConfig.get<string>('loginRoute') : 'login';
|
||||
}
|
||||
|
||||
private getNavigationCommands(redirectUrl: string): any[] {
|
||||
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
||||
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
||||
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
||||
|
||||
return urlSegments.reduce(function(acc, item) {
|
||||
acc.push(item.path, item.parameters);
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user