Angular2使用延迟加载的路由命名路由器插座

时间:2018-03-13 17:06:55

标签: angular angular2-routing router-outlet named-routing

我的主要路线是这样的:

export const routes = [
  {
    path: "",
    component: SiteLayoutComponent,
    //canActivate: [AuthGuard],
    children: [
      { path: "", redirectTo: "/routeA", pathMatch: "full" },
      ...... 
      ......
      {
        path: 'routeA',
        loadChildren: 'app/website/routeA/search/routeA.module#RouteAModule'
      }
    ]
  }
];

然后我的routeA模块路由就像:

const routes: Routes = [
  { path: '', component: SearchComponent,
    children:[
      { path: '', pathMatch: 'full', redirectTo: 'featured'},
      { path: 'search', component: FilterResultComponent, outlet: 'searchResult' },
      { path: 'search/:listId', component: DetailsComponent, outlet: 'searchResult' },
      { path: ':listType', component: ListComponent, outlet: 'jobList' }
    ]
  }


];

我的SearchComponent模板就像:

<search-box></search-box>
<router-outlet name="searchResult"></router-outlet>
<!-- Body Container -->
<div class="container">
  <div class="row">

    <div class="col-sm-8">


      <!-- Job Lists Section -->
      <section class="job-list">
        <div role="tabpanel" class="custom-tab">
          <!-- Nav tabs -->
          <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" [class.active]="activeTab === 'featured'" routerLinkActive="" [routerLinkActiveOptions]="{exact: true}">
              <a [routerLink]="['featured']" aria-controls="featured" role="tab" data-toggle="tab"><i class="material-icons">&#xE885;</i> Featured Jobs</a>
            </li>
            <li role="presentation" [class.active]="activeTab === 'female-only'">
              <a [routerLink]="['female-only']" aria-controls="female" role="tab" data-toggle="tab"><i class="material-icons">&#xE87C;</i> Female Only</a>
            </li>
            <li role="presentation" [class.active]="activeTab === 'expiring-today'">
              <a [routerLink]="['expiring-today']" aria-controls="expiring" role="tab" data-toggle="tab"><i class="material-icons">&#xE01B;</i> Expiring Today</a>
            </li>
          </ul>

          <!-- Tab panes -->
          <div class="tab-content">
            <router-outlet name="jobList"></router-outlet>
          </div>
        </div>
      </section>
      <!-- End Lists Section -->
    </div
 </div>

我想要的是加载routeA模块作为主路由的默认路由,而routeA模块内部的特色路由是我的默认路由,它是路由参数而不是:listType,并且默认情况下会选中featured标签。 但是当我点击search-box组件的搜索按钮时,我应该导航到search路由,并加载filterResultComponent,我想要做的是: 1-显示ListComponent路由器插座内的标签内容jobList,其他组件应位于'searchResult'插座内,我应该隐藏'ListComponent'和标签。 我应该如何使用路由器插座?

0 个答案:

没有答案