I want to load a different set of domains at launch if a user is on a subdomain (test.example.com), versus being on a domain (example.com). However, my code keeps defaulting to the domainRoutes without the facility to allow the user to browse (as all the routes don't exist). How can I fix this?
const routes: Routes = [
{
matcher: (url) => {
if (isOnDomain()) {
return { consumed: url };
}
return null;
},
loadChildren: './modules/website/website.module#WebsiteModule'
},
{
matcher: (url) => {
if (!isOnDomain()) {
return { consumed: url };
}
return null;
},
loadChildren: './modules/main/main.module#MainModule'
}
];
const isOnDomain = () => {
const full = window.location.host;
const parts = full.split('.');
let result = true;
if (parts[0] && parts[1] && parts[2]) {
result = false;
}
console.log(result);
return result;
};
@NgModule({
declarations: [
AppComponent
],
imports: [
RouterModule.forRoot(routes)
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule {
}