Angular 2 - Submodule routing and nested

后端 未结 3 1755
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 08:46

I\'m looking for a solution with Angular 2 for the scenario explained below:

In this scenario, the top-nav contains links to load submodules and sub-nav has

3条回答
  •  失恋的感觉
    2020-12-07 09:48

    The html page will look like this.

    Main Page

    
    
    

    Sub Module Page

    
    
    

    on clicking navigation in top-nav bar the main route outlet will route respectively.

    while clicking on sub-navbar the router-outlet [sub] will route respectively.

    HTML is fine, the trick will came at writing app.routing

    app.routing.ts

    const appRoutes: Routes = [
      {
        path: 'login',
        component: LoginComponent
      },
      { path: 'home',
        component: homeComponent,
        children: [
          {
            path: 'module1',
            component: module1Component,
            children: [
              {
                path: 'submodule11',
                component: submodule11Component,
              },
              {
                path: '',
                redirectTo: 'submodule11',
                pathMatch: 'full'
              }
            ]
          },
          {
            path: 'module2',
            component: module2omponent,
            children: [
              {
                path: 'submodule21',
                component: submodule21Component,
              },
              {
                path: '',
                redirectTo: 'submodule21',
                pathMatch: 'full'
              }
            ]
          }
        ]
      },
      {
        path: 'about',
        component: aboutComponent
      }
    ]
    

    Hope it will help you.

    More details https://angular.io/guide/router

提交回复
热议问题