Angular rolling doesn't work.



  • I'm looking at rolling rolls in Angular. File app-routing.module.ts, imports are dropping

    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 { }

    There is also a separate module admin.module.ts in which another rolling stock is implemented.

    @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{

    }

    By view of the view when he comes to the localhost:4200/admin, he is transferred to the localhost:4200/admin/login page
    I'm thrown at localhost:4200

    What did I miss?



  • I found a solution, Angular changed the syntax loadChildren, so it is necessary to amend app-routing.module.ts:

    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: () => import('./admin/admin.module').then(m => m.AdminModule)
      }
    ];
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2