Guest User

Untitled

a guest
Nov 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Router, NavigationExtras } from '@angular/router';
  3.  
  4. @Injectable()
  5. export class FixRoute {
  6.  
  7. constructor(
  8. private router: Router
  9. ) {}
  10.  
  11. navigate(paths: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean> {
  12. if (!extras.relativeTo) {
  13. return this.router.navigate(paths, extras);
  14. }
  15.  
  16. let segments = extras.relativeTo.snapshot.pathFromRoot.slice(1).map(p => p.routeConfig.path);
  17. paths.forEach(s => {
  18. const pathParts = s.split('/');
  19. pathParts.forEach(p => {
  20. if (p !== '..' && p != '.') {
  21. segments.push(p);
  22. } else if (s !== '.') {
  23. segments.pop()
  24. }
  25. });
  26. });
  27.  
  28. extras = Object.assign({}, extras);
  29. delete extras.relativeTo;
  30. return this.router.navigate(segments, extras);
  31. }
  32. }
Add Comment
Please, Sign In to add comment