My initial domain is localhost:4200 and which in redirects me to some page, based on my routing, but I want to input an invalid domain for example localhost:4200/Whasup or localhost:4200/Whasdown, where Whasup and whasdown page doesn't exist. Before i get redirected to default Angular 404 page, I need to check some conditions. And if my condition doesn't satisfy then i want to redirect it to 404 page else i want to handle it.
my app-routing.module.ts (Auth Guard Checks if the user is logged in or Not)
const routes: Routes = [
// Fallback when no prior route is matched
// Shell.childRoutes([]),
// { path:'home', component: HomeComponent},
// { path: '**', redirectTo: '', pathMatch: 'full' }
Shell.childRoutes([
{ path: '', component: RedirectToComponent, canActivate: [AuthGuard] },
{
path: 'dashboard',
loadChildren: 'src/app/dashboard/dashboard.module#DashboardModule',
canActivate: [AuthGuard]
},
{
path: 'exec-dashboard',
loadChildren:
'src/app/exec-dashboard/exec-dashboard.module#ExecDashboardModule',
canActivate: [AuthGuard]
},
{
path: '**',
redirectTo: '',
canActivate: [AuthGuard]
}
]),
{
path: 'auth',
loadChildren: 'src/app/auth/auth.module#AuthModule',
canActivate: [AuthGuard]
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, {
enableTracing: false, // Enable for debug purpose.
useHash: true,
preloadingStrategy: PreloadAllModules
})
],
exports: [RouterModule],
providers: [AuthGuard]
})
I have also implemented KeyCloak Angular interceptor which helps me get to the keycloak login page, if user is not logged. I have providers defined in app.module.ts.
providers: [
{
provide: APP_INITIALIZER,
useFactory: initializer,
multi: true,
deps: [KeycloakService]
}
],
So whenever I hit my initial domain(localhost:4200), intializer function gets called before i get redirected to any page, same should happen with invalid sub-domain url(localhost:4200/Whasup). Edit: Can i implement above mentioned by any chance, or can i implement sub domain logic in angular, for example, tenant1.localhost:4200 or tenant2.localhost:4200 , (when deployed it would be tenant1.mycompany.com). Can someone suggest me a way to implement sub domain routing in angular. Thanks Much.