I watch videos on YouTube on routing in Angular. The app-routing.module file.ts, I omit the imports
const routes: Routes = [
{
path: '', component: MainLayoutComponent, children: [
{path: '', redirectTo: '/', pathMatch: 'full'},
{path: '', component: MainPageComponent},
{path: 'product/:id', component: ProductPageComponent},
{path: 'cart', component: CartPageComponent}
]
},
{
path: 'admin', loadChildren: './admin/admin.module#AdminModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Next, a separate admin.module is created there.ts, which implements another routing
@NgModule({
declarations: [
AdminLayoutComponent,
LoginPageComponent,
DashboardPageComponent,
AddPageComponent,
EditPageComponent,
OrdersPageComponent,
],
imports:[
CommonModule,
RouterModule.forChild([
{
path: '', component: AdminLayoutComponent, children: [
{path: '', redirectTo: '/admin/login', pathMatch: 'full'},
{path: 'login', component: LoginPageComponent},
{path: 'dashboard', component: DashboardPageComponent},
{path: 'add', component: AddPageComponent},
{path: 'orders', component: OrdersPageComponent},
{path: 'product/:id/edit', component: EditPageComponent},
]
}
])
],
exports: [RouterModule]
})
export class AdminModule{
}
According to the lesson, when he goes to the address localhost:4200/admin, he is thrown to the page localhost:4200/admin/login. And throws me to localhost:4200
What did I miss?
loadChildren: () => import('./items/items.module').then(m => m.ItemsModule). Refers to angular.io/guide/lazy-loading-ngmodules. Also, try to replaceredirectTo: '/admin/login'withredirectTo: 'login'ng g module login --module account --route login. However, remove theimports: [LoginModule]fromAccountModule(for example)