OwenKelvin/Angular-School-Management-System

View on GitHub
src/app/core/services/routes/routes.service.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';

@Injectable({
  providedIn: 'root'
})
export class RoutesService {

  constructor(private router: Router) { }
  getRoutes(): object {
    let returnObj = {};
    this.router.config.filter(route => {
      return route.path !== '' && !/(\*)(\*)/i.test(route.path);
    }).map(route => {
      const obj = {};
      const key = `${route.path}`;
      const component = route.component;
      obj[key] = component;
      return obj;
    }).forEach(route => {
      returnObj = { ...route, ...returnObj };
    });
    return returnObj;
  }
}