I've the following path's in my angular application, For home path base href is set to /home/ and for create /create/
http://localhost:3000/home/account
https://localhost:3000/create/account
Dynamic Route Config path,
export const AppRoute = {
'homeRoutes': [
{ path: 'account', loadChildren: () => import('@home').then(m => m.HomeModule) },
{ path: 'test', loadChildren: () => import('@test').then(m => m.TestModule) },
{ path: '**', component: PageNotFoundComponent }
],
'createRoutes': [
{ path: 'account', loadChildren: () => import('@create').then(m => m.CreateModule) },
{ path: 'login-test', loadChildren: () => import('@logintest').then(m => m.LoginTestModule) },
{ path: '**', component: PageNotFoundComponent }
]
};
In AppComponent.ts
resetRouter () {
const baseHref = this.platformLocation.getBaseHrefFromDOM();
if (baseHref.match('/home/')) {
this.router.resetConfig(routes.homeRoutes);
}
if (baseHref.match('/create/')) {
this.router.resetConfig(routes.createRoutes);
}
}
In Routing Module
const routes = [
{ path: 'home/account', loadChildren: () => import('@home').then(m => m.HomeModule) },
{ path: 'create/account', loadChildren: () => import('@home').then(m => m.HomeModule) },
{ path: 'test', loadChildren: () => import('@test').then(m => m.TestModule) },
{ path: 'login-test', loadChildren: () => import('@logintest').then(m => m.LoginTestModule) },
{ path: 'page-not-found', component: PageNotFoundComponent }
];
So now the problem is,
My app now is now accessible only in http://localhost:3000/home/home/account which is not expected.
Also, If as access to create routes f.e http://localhost:3000/home/test works , but actual expectation is to throw error page.
Please help me configure these routes.
baseHrefat/and make a route that captures bothhomeandcreate. In that component you can check theActivatedRouteand figure out whether you're in home or create, and in the HTML template display different content/components...http://localhost:3000/MyAPP, root is not belong to angularbaseHref = '/MyAPP'and it becomeshttp://localhost:3000/MyAPP/home/accountandhttp://localhost:3000/MyAPP/create/account. That doesn't really matter