File

projects/maplander/shared/src/lib/services/router-history/router-history.service.ts

Index

Methods

Methods

Public getLastPath
getLastPath(ar: ActivatedRoute, indexesToRemove: number)
Parameters :
Name Type Optional
ar ActivatedRoute No
indexesToRemove number No
Returns : string
import {Injectable} from '@angular/core';
import {ActivatedRoute} from '@angular/router';

@Injectable()
export class RouterHistoryService {

  public getLastPath(ar: ActivatedRoute, indexesToRemove: number): string {
    let url = '';
    try {
      const routerLink = ar.parent.snapshot.pathFromRoot
        .map((s) => s.url)
        .reduce((a, e) => {
          // Do NOT add last path!
          if (a.length + e.length !== ar.parent.snapshot.pathFromRoot.length) {
            return a.concat(e);
          }
          return a;
        })
        .map((s) => s.path);
      while (indexesToRemove > 0) {
        routerLink.splice(routerLink.length - 1, 1);
        indexesToRemove--;
      }
      routerLink.forEach(item => {
        url += `/${item}`;
      });
    } catch (e) {
      url = '/';
    }
    return url;
  }

}

result-matching ""

    No results matching ""