Call function in page.route

Viewed 69

actually I have this file that returns an arrangement with the web menus

menu-items.ts

import { Injectable } from '@angular/core';
import { ConfMenu } from 'src/app/_models/conf-menu/conf-menu';
import { ConfMenuService } from '../../_services/conf-menu.service'


@Injectable()
export class MenuItems {

  MenusBd!: ConfMenu[];
  constructor(private menuService: ConfMenuService) 
  { 
    this.menuService.list().subscribe(data => {
      this.MenuBd = data.sort((a,b) => a.position - b.position);
    })
  }

  getMenuitem(): ConfMenu[] {
    return this.MenuBd;
  }
}

And I want to use this in the

page.routing.ts

import { Routes } from '@angular/router';
import { AuthGuard } from './_helpers/auth.guard';

export const AppRoutes: Routes = [
  {
    path: '',
    component: FullComponent,
    children: [
      {
        path: 'config',
        loadChildren: () => import('./pages/configuration/configuration.module').then(m => m.ConfigurationModule),
        canActivate: [AuthGuard], rol: {}
      },
      { path: '**', redirectTo: '/home' }
    ]
  }
];

The idea is call the function an use a for to match the path from function with the AppRoutes path to add the rol in the array

for example, something like that

AppRoutes.forEach(x => {
  valuesFromFunction.forEach(y => {
    if(x.path == y.path){
      x.data = {rol: y.rol}
    }
  });  
});

Is possible this? or maybe exist another form more easy ?

Thx a lot

0 Answers
Related