美文网首页
Augular 路由

Augular 路由

作者: 米诺zuo | 来源:发表于2021-03-05 11:58 被阅读0次

### 路由配置

```

import { NgModule } from '@angular/core';

import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [

  {

    path: '',  redirectTo: 'home', pathMatch: 'full'

  },

  {

    path: 'home', component: HomeComponent,

  },

  {

    path: 'about', component: AboutComponent,

  },

{

    path: 'tutorial', component: TutorialComponent,

    children: [

      {

        path: '', redirectTo: 'started', pathMatch: 'full'

      },

      {

        path: 'started', component: TutorialStartedComponent

      },

      {

        path: 'model/api', component: TutorialModelComponent

      },

      {

        path: 'topic/analysis/ae', component: TutorialAnalysisComponent,

      },

      // {

      //  path: 'model/:key', component: TutorialModelComponent

      // },

      // {

      //  path: 'topic/:key/:sub', component: TutorialAnalysisComponent,

      // },

    ]

  },

];

@NgModule({

  imports: [RouterModule.forRoot(routes)],

  exports: [RouterModule],

})

export class AppRoutingModule { }

```

### 组件

#### slide 组件

```

<div class="nav-contain-tutorial">

    <div class="nav-item"  *ngFor="let link of links" >

      <div class="large">

        <img *ngIf="!rla.isActive" [src]="'../../assets/images/'+ link.icon +'.png'">

        <img  *ngIf="rla.isActive"  [src]="'../../assets/images/'+ link.icon + '_selected.png'">

        <!-- <img [src]="'../../assets/images/'+link.icon+'.png'"> -->

        <a  class="title" [routerLink]="link.path" routerLinkActive="story-span-active" #rla="routerLinkActive"> {{link.label}}</a>

        <div *ngIf="link.children && link.children.length>0" >

          <div  *ngFor="let child of link.children">

          <a  [routerLink]="child.path" routerLinkActive="story-span-active" class="sub"  #rla="routerLinkActive">

            <span class="third_child" [ngClass]="{'third_link': child.children, 'third_link-active':rla.isActive && child.children}"></span>

            {{child.label}}</a>

            <ng-container *ngIf="child.children && child.children.length>0">

              <ng-container  *ngFor="let third of child.children">

                <a  [routerLink]="third.path" routerLinkActive="story-span-active" class="sub third"  #rla="routerLinkActive">{{third.label}}</a>

              </ng-container>

            </ng-container>

          </div>

        </div>

      </div>

    </div>

  </div>

```

#### ts

```

this.links = [

      new NavLink('Getting Started', 'started', 'GettingStarted'),

      new NavLink('General model usage', 'model', 'Advanced_topics', [

        new NavLink('Use model API', 'model/api'),

        new NavLink('Configure your model', 'model/config'),

        new NavLink('Customize your model', 'model/custome'),

        new NavLink('Contribute your model', 'model/contribute')

      ]),

      new NavLink('Advanced Topics', 'topic', 'generalmodelusage', [

        new NavLink('Time-series analysis ', 'topic/analysis', '', [

          new NavLink('Auto-encoder', 'topic/analysis/ae')

        ]),

        new NavLink('Computer Vision', 'topic/vision', '', [

          new NavLink('Object Detection ', 'topic/vision/od')

        ])

      ]),

    ];

```

### NavLink  model

```

export class NavLink {

    constructor(

      public label: string,

      public path: string,

      public icon?: string,

      public children?: Array<NavLink>,

    ) { }

  }

```

### 路由出口

```

  <router-outlet></router-outlet>

```

### 获取当前路由

```

this.route.snapshot.routeConfig.path;

this.route.paramMap.subscribe((params: ParamMap) => {

        console.log(params.get('nav'), params.get('key'));

}

```

相关文章

  • Augular 路由

    ### 路由配置 ``` import { NgModule } from '@angular/core'; im...

  • augular2

    https://github.com/angularclass/angular2-webpack-starter#...

  • Augular 相关链接汇总

    官网 Angular 英文网 Angular 中文网 Angular Cli 文档 Angular Cli (Gi...

  • vue基础知识

    引子 前端三大框架: +Angular Google Angular.js(1.x) Augular(2.x) +...

  • 1、Vue.js起步学习

    Vue.js的官网定义:渐进式JavaScript框架 前端三个框架:Augular React VueMVVM...

  • Angular项目 ng serve open 失败

    记录一下,以防下次又忘记错误。 解决方法: 方法一:根据错误提示,npm install @augular-dev...

  • Angular 中的 ElementRef

    ElementRef 顾名思义是元素参阅。 其实在实际应用中就是获取视图层的dom元素,借助Augular提供的依...

  • Augular2断点调试ts文件

    今天又学到一个东西,记录下来,有需要的小伙伴也可参考一下,大家可以互相学习哈。 1、首先下载在插件商店下载debu...

  • React 还是 Vue: 你应该选择哪一个Web前端框架?

    2016年,React在Web端和移动端都实现了迅速的成长,稳稳地领先于其主要竞争对手Augular,巩固了其作为...

  • VueJS与ReactJs,如何选择

    2016年,React在Web端和移动端都实现了迅速的成长,稳稳地领先于其主要竞争对手Augular,巩固了其作为...

网友评论

      本文标题:Augular 路由

      本文链接:https://www.haomeiwen.com/subject/xdxefftx.html