Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Router, NavigationExtras } from '@angular/router';
- @Injectable()
- export class FixRoute {
- constructor(
- private router: Router
- ) {}
- navigate(paths: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean> {
- if (!extras.relativeTo) {
- return this.router.navigate(paths, extras);
- }
- let segments = extras.relativeTo.snapshot.pathFromRoot.slice(1).map(p => p.routeConfig.path);
- paths.forEach(s => {
- const pathParts = s.split('/');
- pathParts.forEach(p => {
- if (p !== '..' && p != '.') {
- segments.push(p);
- } else if (s !== '.') {
- segments.pop()
- }
- });
- });
- extras = Object.assign({}, extras);
- delete extras.relativeTo;
- return this.router.navigate(segments, extras);
- }
- }
Add Comment
Please, Sign In to add comment