Page MenuHomec4science

route-updater.ts
No OneTemporary

File Metadata

Created
Tue, Apr 30, 11:56

route-updater.ts

import { Router, ActivatedRoute, Params } from '@angular/router';
import { Mapping, RouteReader } from './route-reader';
export class RouteUpdater extends RouteReader {
protected mapping: Mapping;
protected routerParams: Params;
protected currentRoute: string;
parentActivatedRoute: ActivatedRoute;
constructor(protected router: Router, protected activatedRoute: ActivatedRoute ) {
super(router, activatedRoute);
if(this.currentRoute == undefined || this.currentRoute == null){
this.currentRoute = (this.activatedRoute.snapshot.routeConfig != null)
? this.activatedRoute.snapshot.routeConfig.path : null;
}
}
protected updateParams(launch?: boolean) {
let newRouterParam = {};
for(let key of Object.keys(this.mapping)){
let paramsKey = this.mapping[key]['param'];
if(this[key] != null){
if (Array.isArray(this[key]) && this[key].length > 0){
newRouterParam[paramsKey] = JSON.stringify(this[key]);
} else {
newRouterParam[paramsKey] = this[key];
}
}
}
for(let key of Object.keys(this.routerParams)){
if(newRouterParam[key] == null){
newRouterParam[key] = this.routerParams[key];
}
}
let parentActivatedRoute = (this.activatedRoute.parent != null) ? this.activatedRoute.parent : this.parentActivatedRoute;
if(parentActivatedRoute != undefined && parentActivatedRoute != null){
parentActivatedRoute.url.subscribe(url=>{
let parentPath = url[0].path;
if (launch != undefined && launch){
let link = this.router.createUrlTree([ parentPath + '/' + this.currentRoute], { queryParams: newRouterParam });
window.open(link.toString(), '_blank')
} else {
this.router.navigate([ parentPath + '/' + this.currentRoute], { queryParams: newRouterParam });
}
});
} else {
if (launch != undefined && launch){
let link = this.router.createUrlTree([ this.currentRoute], { queryParams: newRouterParam });
window.open(link.toString(), '_blank')
} else {
this.router.navigate([ this.currentRoute], { queryParams: newRouterParam });
}
}
}
}

Event Timeline