I edit my answer so maybe I get you into the right direction.
As I understand you have 2 requirements.
1) Identify if the visitor is UserA or UserB
2) Change behaviour of the website depending on UserA or UserB
First of all to identify the user we should pass some parameter from referer site. Normally this should be done with an SSO mechanism (token, etc). But in this case to simplify the case with stay with an Querystring parameter.
User A: http://yoursite.com?user=a
User B: http://yoursite.com?user=b
So now we can identify if we are "talking" with User A or User B.
From now on we can customize the entire application with our needs:
Different Layouts, Different routings etc.
To have different routes configured on specific use cases what you could do is to configure different route definitions.
const standardRoutes: Routes = [
{
path: 'main',
loadChildren: 'app/main/standard/some.module#SomeModule',
canActivate: [AuthenticationGuard]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: 'main/standard'
}
]
const AUserRoutes: Routes = [
{
path: 'main',
loadChildren: 'app/main/a_user/some.module#SomeModule',
canActivate: [AuthenticationGuard]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: 'main/a_user_url'
}];
const BUserRoutes: Routes = [
{
path: 'main',
loadChildren: 'app/main/b_user/some.module#SomeModule',
canActivate: [AuthenticationGuard]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: 'main/b_user_url'
}];
Then in App Module to handle the different Users (if there is a need to define different routings - normally only needed in some very special cases)
const standardRoutes: Routes = [
{
path: 'main',
loadChildren: 'app/main/standard/some.module#SomeModule',
canActivate: [AuthenticationGuard]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: 'main/standard'
}
]
const AUserRoutes: Routes = [
{
path: 'main',
loadChildren: 'app/main/a_user/some.module#SomeModule',
canActivate: [AuthenticationGuard]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: 'main/a_user_url'
}];
const BUserRoutes: Routes = [
{
path: 'main',
loadChildren: 'app/main/b_user/some.module#SomeModule',
canActivate: [AuthenticationGuard]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: 'main/b_user_url'
}];
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
RouterModule.forRoot(standardRoutes, {
enableTracing: false
}),
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule {
public constructor(
private router: Router
) {
const user = router.routerState.snapshot.root.queryParams.user;
if (user === 'a') {
router.resetConfig(AUserRoutes);
} else if (user === 'b') {
router.resetConfig(BUserRoutes);
}
}
}