question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redirectTo is not working for children routes.

See original GitHub issue

I using the shared module with lazy loading of modules. While I am importing my shared module in all modules and *ngxPermissionsOnly is working is fine.

import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgxPermissionsModule } from 'ngx-permissions';

@NgModule({
  imports: [
    CommonModule,
    NgxPermissionsModule.forRoot()
  ],
  declarations: [],
  exports: [
    // Modules
    CommonModule,
    NgxPermissionsModule
  ]
})
export class SharedModule {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: SharedModule,
      providers: [
       
      ]
    };
  }
}
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AuthGuard } from './shared/guards/auth.guard';

const routes: Routes = [
  {
    path: '', loadChildren: './user/user.module#UserModule', canActivate: [AuthGuard]
  },
  {
    path: 'auth', loadChildren: './auth/auth.module#AuthModule'
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { UserComponent } from './user.component';
import { NgxPermissionsGuard } from 'ngx-permissions';
import { Get103EntryResloveService } from './entry-one-zero-three/get-103-entry-reslove.service';

const routes: Routes = [
  {
    path: '',
    component: UserComponent,
    canActivateChild: [NgxPermissionsGuard],
    children: [
      {
        path: '',
        pathMatch: 'full',
        redirectTo: 'dashboard',
      },
      {
        path: 'dashboard',
        loadChildren: './dashboard/dashboard.module#DashboardModule',
        data: {
          permissions: {
            only: ['101', '102'],
            redirectTo: '/auth/login'
          }
        }
      },
      {
        path: 'employee',
        loadChildren: './employee/employee.module#EmployeeModule',
        data: {
          permissions: {
            only: ['101', '102'],
            redirectTo: '/auth/login'
          }
        }
      },
      {
        path: 'entry-103',
        loadChildren: './entry-one-zero-three/entry-one-zero-three.module#EntryOneZeroThreeModule',
        resolve: {
          get103Entry: Get103EntryResloveService
        },
        data: {
          permissions: {
            only: ['101', '102', '107'],
            redirectTo: '/auth/login'
          }
        }
      },
      {
        path: 'entry-105',
        loadChildren: './entry-one-zero-five/entry-one-zero-five.module#EntryOneZeroFiveModule',
        data: {
          permissions: {
            only: ['101', '102', '107'],
            redirectTo: '/auth/login'
          }
        }
      },
      {
        path: 'address-verification',
        loadChildren: './address-verification/address-verification.module#AddressVerificationModule',
        data: {
          permissions: {
            only: ['101', '102', '103', '104', '105', '106'],
            redirectTo: '/auth/login'
          }
        }
      },
      {
        path: 'reports',
        loadChildren: './reports/reports.module#ReportsModule',
        data: {
          permissions: {
            only: ['101', '102', '103'],
            redirectTo: '/auth/login'
          }
        }
      }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class UserRoutingModule {}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexKhymenkocommented, Jul 25, 2018
0reactions
faradoxuzcommented, Jun 28, 2020

same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 routing redirect to with child routes - Stack Overflow
I have been the same problem. It seems an Angular tricks: If you remove leading slash in 'redirectTo' field, your application will be...
Read more >
redirectTo doesn't work in children routes config #1461 - GitHub
I have below routes configured: const routes: Routes = [ { path: "", redirectTo: ... redirectTo doesn't work in children routes config #1461....
Read more >
Angular 10 routing this is what you need to know
Getting started with the Angular routing components. ... Navigating to a route; Fallback routes; Redirect; Child routes.
Read more >
Troubleshooting Angular routing - Medium
Why? It is as simple as that: “Note that no further redirects are evaluated after an absolute redirect.” So if Angular does not...
Read more >
Angular Router: Child Routes, Auxiliary Routes, Master Detail
Learn how to use the Angular Router, avoid common pitfalls, learn Child Routes, Auxiliary Routes, setup a Master Detail Routing Scenario.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found