RouterModule.forRoot(ROUTES) vs RouterModule.forChild(ROUTES)

后端 未结 5 610
离开以前
离开以前 2020-11-28 18:37

What is the differences between these two and what are the use cases for each?

The docs aren\'t exactly helpful:

forRoot creates a module that con

5条回答
  •  温柔的废话
    2020-11-28 18:49

    If appRoutes contains path to various functions in the site (admin crud, user crud, book crud) and we want to separate them we could simply do that :

     imports: [
        BrowserModule, HttpModule,
        AppRoutingModule,
        RouterModule.forRoot(categoriesRoutes),
        RouterModule.forRoot(auteursRoutes),
      ],
    

    And for routes :

    const auteursRoutes:Routes=[
      {path:'auteurs/ajouter',component:CreerAuteurComponent},
    ]
    const categoriesRoutes: Routes = [
    
    
      {path:'categories/consulter',component:ConsultercategoriesComponent},
      {path:'categories/getsouscategoriesbyid/:id',component:GetsouscategoriesbyIDComponent},
      {path:'categories/ajout',component:CreerCategorieComponent},
     {path:'categories/:id',component:ModifiercategorieComponent},
     {path:'souscategories/ajout/:id',component:AjoutersouscategorieComponent},
     {path:'souscategories/lecture/:id1',component:SouscategoriesComponent},
     {path:'souscategories/modifier/:id1',component:ModifiersupprimersouscategorieComponent},
      {path:'uploadfile',component:UploadfileComponent},
      {path:'categories',component:ConsultercategoriesComponent},
    
    
    
    ]
    

提交回复
热议问题