简体   繁体   English

子路径为空的角度辅助路线

[英]Angular auxiliary route with an empty path on child

I'm trying to use the auxiliary route on an empty path. 我正在尝试在空路径上使用辅助路线。 For example: 例如:

  {
    path: 'users',
    children: [
      {
        path: '',
        component: UsersComponent,
      },
      {
        path: 'user-details',
        outlet: 'list',
        component: UserDetailsComponent
      },
    ]
  },

And my UsersComponent template: 和我的UsersComponent模板:

<router-outlet></router-outlet>
<router-outlet name="list"></router-outlet>

But when I'm trying to navigate to the following URLs: 1. http://localhost:4200/users(list:user-details) 2. http://localhost:4200/(users//list:user-details) 但是,当我尝试导航到以下URL时:1. http:// localhost:4200 / users(list:user-details) 2. http:// localhost:4200 /(users // list:user-details )

I'm getting this error: 我收到此错误:

Cannot match any routes. 无法匹配任何路线。 URL Segment: 'users' 网址段:“用户”

You are getting that error because you have no component loading for 'users' which you set as your first route. 之所以收到该错误,是因为您没有为“用户”加载任何组件,而这是您设置的第一条路线。 the 'users' route should be defined in your main routing module like this 应该在您的主路由模块中定义“用户”路由,如下所示

{ path: 'users', loadChildren: './users/user.module#UserModule' }

and your current code needs to look like this 您当前的代码应如下所示

const userRoutes: Routes = [
  {
    path: '', component: UsersComponent, children: [
      {
         path: 'user-details',
         outlet: 'list',
         component: UserDetailsComponent
      }
     ]
   }

and that will make the firs route 'users' 这将使冷杉路线成为“用户”

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

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