Does angular2 support nested states/routes?

后端 未结 2 1820
不思量自难忘°
不思量自难忘° 2020-12-25 10:11

Does angular2 support nested states/routes? for example in a view port there are 2 links and on clicking a specific link it will present a view which with further have more

2条回答
  •  甜味超标
    2020-12-25 10:51

    Yes.

    I made some demo: 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: `
        

    Product {{pid}}

    Show Info Go Buy
    ` }) @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, PersistentRouterOutlet] , template: ` ` }) @RouteConfig([ {path: '/', name: 'StoreInfo', component: StoreInfo, useAsDefault: true} {path: '/product/:pid/...', name: 'Product', component: Product} ]) export class App { }

    Here's the doc: https://angular.io/docs/ts/latest/guide/router.html#!#child-router

    Note there's a problem with persistent tabs: Angular2 Routing: persisting route tabs and child routes https://github.com/angular/angular/issues/6634

提交回复
热议问题