[ADF-2904] Search - redirect breaks application (#3268)

* set navigation commands over plain string

* fix test

* lint
This commit is contained in:
Cilibiu Bogdan
2018-05-08 16:46:35 +03:00
committed by Eugenio Romano
parent c90ad3f875
commit d456b3cba1
12 changed files with 205 additions and 105 deletions

View File

@@ -17,8 +17,8 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot, CanActivate, CanActivateChild,
RouterStateSnapshot, Router
ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot,
Router, PRIMARY_OUTLET, UrlTree, UrlSegmentGroup, UrlSegment
} from '@angular/router';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthenticationService } from './authentication.service';
@@ -42,7 +42,9 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild {
return true;
}
this.authService.setRedirectUrl({ provider: 'BPM', url: redirectUrl });
const navigation = this.getNavigationCommands(redirectUrl);
this.authService.setRedirect({ provider: 'BPM', navigation });
const pathToLogin = this.getRouteDestinationForLogin();
this.router.navigate(['/' + pathToLogin]);
@@ -54,4 +56,15 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild {
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;
}, []);
}
}