Is it possible to have multiple level Nested Route

2019-08-15 02:11发布

Is it possible to have multiple level nesting for angular routing. I am trying to achieve below but it says [Child routes are not allowed for "/cash/..". Use "..." on the parent's route path].

Intended route

/storeselector /forms - shows all forms /forms/cash/ - user select cash form from list of forms and on load it will shows all orders /forms/cash/id:1/ shows order details /forms/cash/edit/1 edit order 1

below is my code.

app component

@Component({
    selector : 'forms-app',
    templateUrl : 'app/app.component.html', 
    styleUrls : ['app/app.component.css'],
    directives: [ROUTER_DIRECTIVES],
    providers: [HTTP_PROVIDERS]
})
@RouteConfig([
  { path: '/storeselector', name: 'StoreSelector', component: StoreSelectorComponent, useAsDefault: true },
  { path: '/forms/...', name: 'Forms', component: FormsComponent }
])

forms component

@Component({
    selector : 'forms-root',
    template: '<router-outlet></router-outlet>',
    directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
  { path: '/', name: 'Forms', component:FormsListComponent, useAsDefault: true },
    { path: '/cash/..', name: 'CashForm', component:CashFormOrderComponent, useAsDefault: false}
])
export class FormsComponent {
  constructor(private _logger : LogService) {
    this._logger.info("FormsComponent loaded");
  }
}

cashform components
@Component({
    selector : 'forms-cash',
    template: '<div></div>',
    directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
  { path: '/', name: 'Orders', component:CashOrdersListComponent, useAsDefault: true },
    { path: '/:id', name: 'Order', component:CashOrderComponent },
  { path: '/edit/:id', name: 'Order', component:CashOrderComponent  }
])
export class CashFormOrderComponent {
  constructor(private _logger : LogService) {
    this._logger.info("CashFormOrderComponent loaded");
  }
}

1条回答
对你真心纯属浪费
2楼-- · 2019-08-15 02:42
{ path: '/cash/..', name

should be

{ path: '/cash/...', name

To indicate there are child routes 3 . are required

查看更多
登录 后发表回答