I am using RouterModule, I have this in my app.module.ts
const appRoutes: Routes = [
{ path: '', redirectTo: 'mainMenu', pathMatch: 'full' },
{ path: 'mainMenu', component: MainComponent,
children: [
{
path: '',
redirectTo: 'products',
pathMatch: 'full'
},
{
path: 'products',
component: ProductsComponent
}
]
},
{ path: 'targeting', component: TargetingComponent }
];
It works really fine when I'm testing locally. /mainMenu/products takes me to the MainComponent and it includes the ProductsComponent. and /targeting takes me to the TargetingComponent as well.
I built the project using
ng build --aot
The generated files in dist were placed on the server. The page automatically redirects to /mainMenu/products. But if I enter in the URL /mainMenu/products or /targeting it does not work. I get GET /mainMenu/products" Error (404): "Not found"
or GET /targeting" Error (404): "Not found"
. So I assume this is happening because of the ahead of time compilation, is this true? Is there anything I should do in the configuration for this to work?
I'm using npm http-server.