简体   繁体   English

如何在Angular2上默认从子路径加载组件

[英]How to load components from child path by default on Angular2

I have a child route path in my @NgModule defined as: 我的@NgModule中有一个子路由路径,定义为:

RouterModule.forRoot([
  {
    path: '',
    redirectTo: 'orders',
    pathMatch: 'full'
  },
  {
    path: 'orders',
    component: ListComponent,
    children: [
      {
        path: 'view/:id',
        component: ViewOrderComponent
      },
    ]
  }
]),

The problem i have is that when i load in the browser the page /orders loads fine, when i navigate to /orders/view/100 still works, but if i refresh the browser(with the url /orders/view/100) it loads but goes to /orders, it doesnt load /orders/view/100 as expected, i now is loading the page /orders/view/100 because i can see in the Chrome dev tools, but after loading it goes to /orders. 我的问题是,当我在浏览器中加载页面/ orders时,加载得很好,当我导航至/ orders / view / 100时仍然有效,但是如果我刷新浏览器(使用url / orders / view / 100),加载但转到/ orders,它没有按预期加载/ orders / view / 100,我现在正在加载/ orders / view / 100页面,因为我可以在Chrome开发工具中看到它,但是加载后转到/ orders。

How can i make that after loading the route orders it also loads the route orders/view? 在加载路径订单后如何使它也加载路径订单/视图?

Okay try this. 好吧,尝试一下。 On your second path definition make it an absolute path, "/orders" 在第二条路径定义上,将其设为绝对路径,“ / orders”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM