redirectTo is not working for children routes.
See original GitHub issueI 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:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rajguru827 Thats probably you are using lazy routes. ITs better to use https://github.com/AlexKhymenko/ngx-permissions/wiki/Usage-with-routes#can-load-guard
same issue