微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular2是否支持嵌套状态/路由?

angular2是否支持嵌套状态/路由?
例如在视图端口中有2个链接,并且在点击特定链接时,它将呈现进一步具有多于一个链接但是特定于较早链接的视图。
是。

我做了一些演示:
http://plnkr.co/edit/IcnEzZ0WtiaY5Bpqrq2Y?p=preview

import {Component,View,Input} from 'angular2/core';
import {
    RouteConfig,Router,RouteParams,ROUTER_DIRECTIVES
} from 'angular2/router';
import {PersistentRouterOutlet} from './persistent-router-outlet';


@Component({})
@View({
  template: 'product info here'
})
class ProductInfo {
}

@Component({})
@View({
  template: 'buy here'
})
class ProductBuy {
}


@Component({})
@View({
  directives: [...ROUTER_DIRECTIVES,PersistentRouterOutlet],template: `
    <div>
      <h2>Product {{pid}}</h2>
      <a [routerLink]="['Info']">Show Info</a>
      <a [routerLink]="['Buy']">Go Buy</a>
      <div>
        <router-outlet></router-outlet>
      </div>
    </div>
  `
})
@RouteConfig([
  {path: '/info',name: 'Info',component: ProductInfo,useAsDefault: true}
  {path: '/buy',name: 'Buy',component: ProductBuy}
])
class Product {
  pid
  constructor(params: RouteParams) {
    this.pid = params.get('pid')
  }
}

@Component({})
@View({
  directives: [...ROUTER_DIRECTIVES],template: `
    info about the store
  `
})
class StoreInfo {
}


@Component({
  selector: 'my-app',providers: [],directives: [...ROUTER_DIRECTIVES,template: `
    <div>
      <a [routerLink]="['./StoreInfo']">See Store Info</a>
      <a [routerLink]="['./Product',{pid:1}]">See Product 1</a>
      <a [routerLink]="['./Product',{pid:2}]">See Product 2</a>
      <div>
        <persistent-router-outlet></persistent-router-outlet>
      </div>
    </div>
  `
})
@RouteConfig([
  {path: '/',name: 'StoreInfo',component: StoreInfo,useAsDefault: true}
  {path: '/product/:pid/...',name: 'Product',component: Product}
])
export class App {
}

这里是文档:https://angular.io/docs/ts/latest/guide/router.html#!#child-router

注意持久标签页有一个问题:Angular2 Routing: persisting route tabs and child routes
https://github.com/angular/angular/issues/6634

原文地址:https://www.jb51.cc/angularjs/145301.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐