具有根标识符和子页面的角度路由

问题描述 投票:1回答:1

我正在尝试定义一个独特的URL结构,但是我似乎无法让孩子/未找到的路由像我期望的那样工作。

例如:

呜呜呜.my site.com/:ID/home WWW.my site.com/:ID/about-US

我构建了一个路由模块,我正在做这样的事情:

const routes: Routes = [
  {
    path: '',
    component: ConciergeComponent,
    pathMatch: 'full'
  },
  {
    component: ConciergeComponent,
    path: ':id',
    children: [{
      path: 'home',
      component: HomeComponent
    }]
  },
  {
    path: '**',
    component: NotFoundComponent
  }
];

如果我导航到www.mysite.com,会按照预期调用礼宾。在将用户重定向到正确的“目标网页”之前,我正在根据业务规则进行一些飞行前检查。

但是,当我导航到/ usr-12 / home时它不起作用,而是它给了我NotFound(当路径不存在时,它会期待)。我觉得我在这里错过了一些非常小的东西?

angular angular2-routing
1个回答
1
投票

试试这个。

const routes: Routes = [
  {
    path: '',
    component: ConciergeComponent,
    pathMatch: 'full'
  },
  {
    component: ConciergeComponent,
    path: ':id/home',
    children: [{
      path: 'home',
      component: HomeComponent
    }]
  }
];
© www.soinside.com 2019 - 2024. All rights reserved.