zoukankan      html  css  js  c++  java
  • AngularJS5.0 (第五篇)--路由

    新建app-routing.module.ts

      

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { RouterModule, Routes } from '@angular/router';
    
    import { LoginComponent } from './components/login/login.component';
    import { VesselComponent } from './components/vessel/vessel.component';
    import { Page404Component } from './components/page404/page404.component';
    import { ArchivesComponent } from './components/archives/archives.component';
    import { SearchComponent } from './components/archives/subs/search/search.component';
    import { CreateComponent } from './components/archives/subs/create/create.component';
    
    const routes: Routes = [
      { path: 'login', component: LoginComponent, data: { name: 'login!' } },
      { path: 'vessel', component: VesselComponent, data: { name: 'vessel!' },
        children: [
          { path: 'archives', component: ArchivesComponent, data: { name: 'archives!' },
            children: [
              { path: 'search', component: SearchComponent, data: { name: 'search!' } },
              { path: 'create', component: CreateComponent, data: { name: 'create!' } },
              { path: '', redirectTo: '/vessel/archives/search', pathMatch: 'full' }
            ]
          },
          // 四个子路由用懒加载方式加载
          // { path: 'archives', loadChildren: './components/archives/archives.module#ArchivesModule' },
          // { path: 'evaluation', loadChildren: './components/evaluation/evaluation.module#EvaluationModule' },
          // { path: 'train', loadChildren: './components/train/train.module#TrainModule' },
          // { path: 'indent', loadChildren: './components/indent/indent.module#IndentModule' },
          { path: '', redirectTo: '/vessel/archives/search', pathMatch: 'full' }
        ]
      },
      { path: '', redirectTo: '/login', pathMatch: 'full' },
      { path: '**', component: Page404Component }
    ];
    
    @NgModule({
      imports: [
        CommonModule,
        RouterModule.forRoot(
          routes,
          // { enableTracing: true } // <-- debugging purposes only
        )
      ],
      exports: [
        RouterModule
      ],
      declarations: []
    })
    export class AppRoutingModule { }

    在app.module.ts中注入自定义的路由表

      

    import { AppRoutingModule } from './app-routing.module'; /*路由模块*/
    imports: [ /*引入当前模块运行依赖的其他模块*/
        BrowserModule,
        FormsModule,
        HttpClientModule,
        AppRoutingModule
      ],
  • 相关阅读:
    java 全组合 与全排列
    (转)java +libsvm 安装与测试:
    ictclas4j 分词工具包 安装流程
    (转)超详细单机版搭建hadoop环境图文解析
    HTML+CSS 滚动条样式自定义
    HTML+CSS之iframe
    思维导图工具 & 原型设计工具
    js setInterval 启用&停止
    jquery 获取 checkbox 的 checked 状态问题
    几个实用的 jQuery 插件
  • 原文地址:https://www.cnblogs.com/sdorm/p/8806089.html
Copyright © 2011-2022 走看看