1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Generating Angular Routes via API

Discussão em 'Angular' iniciado por Jason, Setembro 15, 2025.

  1. Jason

    Jason Guest

    I've looked at previous posts on this which are now somewhat out of date.

    I want to generate my Angular routes via the API backend. The reason for this is so that different routes can be generated based on user role, rather than having a huge routes file.

    The "problem" is that Angular does not maintain its own Component type registry which I can query. Therefore, generating the component of an Angular Route is on me.

    Angular removed its own Component type registry back around Angular 9. My application uses Angular 20.

    The standard response here seems to be to maintain a mapping like Map<string, Type<any>> and manually do the conversion. I'd probably use Record<string, Type<any>> if I went this route. Is this still considered the best way to get what I need?

    I would probably do something like this (I wouldn't really be passing the userId, I have a more secure way implemented):

    getUserRoutes(userId: string): Observable<Route[]> {
    this.dataService.get(ROUTES_API_PATH, {userId: userId })
    .pipe(
    map((routes) => {
    const result = routes.map((item) => {
    return {
    ...item,
    component: registry.get(typeName)
    });
    return result;
    }


    Again, my use case is needing role-specific routes.

    Continue reading...

Compartilhe esta Página