google.com
is the homepage. I need two different routes for the homepage. The first route works while the user is not logged in (Auth) and the second route works while the user is logged in (Dashboard).
The hard part is when both auth and dashboard pages work on a single homepage, not different URLs.
Note: Both modules have multiple components. Auth has (login - signup - reset) components and Dashboard has (index - users - posts) components.
const routes: Routes = [
{
path: 'index',
loadChildren: './modules/index/index.module#IndexModule'
},
{
path: 'error',
loadChildren: './modules/error/error.module#ErrorModule'
},
// Fallback when no prior routes is matched
{ path: '**', redirectTo: 'not-found', pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: false })],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
const routes: Routes = [
{
path: '',
children: [
{
path: '',
loadChildren: './modules/home/home.module#HomeModule',
canLoad: [AuthGuard],
},
{
path: 'auth',
loadChildren: './modules/auth/auth.module#AuthModule',
canLoad: [NoAuthGuard]
},
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class IndexRoutingModule { }
const routes: Routes = [
{
path: '',
component: HomeLayoutComponent,
pathMatch: 'full',
children: [
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full'
},
{
path: 'dashboard',
component: DashboardComponent,
data: { title: 'Dashboard' }
},
]
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class HomeRoutingModule { }
const routes: Routes = [
{
path: '',
component: AuthLayoutComponent,
pathMatch: 'full',
children: [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent,
data: { title: 'Sign In To Admin' }
},
]
}
];
@NgModule({
imports: [
RouterModule.forChild(routes)
],
exports: [
RouterModule
]
})
export class AuthRoutingModule { }
The problem is only with routing, not guards and not anything.