角路由redirectTo参数触发错误:未捕获(承诺)

时间:2019-05-23 06:26:00

标签: javascript angular angular-routing

这是我的route代码-

{ path: 'search',
  children: [
  { path: '', redirectTo: '/products', pathMatch: 'full' },
  { path: ':cat_id/:query', component: SearchComponent }
  ]
},
{ path: 'products',
  children: [
  { path: '', component: ProductsComponent },
  { path: 'compare', component: ProductComparePageComponent },
  { path: ':cat', component: CategoryComponent },
  ]
},

因此,当我将URL设置为/search时,它可以将我重定向到/products URL。但是我在Angular SSR中出现以下错误-

  

ERROR错误:未捕获(承诺):错误       在resolvePromise(... / dist / server.js:1002:31)       在resolvePromise(... / dist / server.js:959:17)

1 个答案:

答案 0 :(得分:0)

我已经给出了带有子路径的路径常数的示例,希望对您有所帮助。

const crisisCenterRoutes: Routes = [
{
  path: 'crisis-center',
  component: CrisisCenterComponent,
  children: [
   {
    path: '',
    component: CrisisListComponent,
    children: [
      {
        path: ':id',
        component: CrisisDetailComponent
      },
      {
        path: '',
        component: CrisisCenterHomeComponent
      }
    ]
  }
]}
];

根据您的代码

{ path: 'search',
  component: 'SomeComponent,
  children: [
   { path: '', redirectTo: '/products', pathMatch: 'full' },
   { path: ':cat_id/:query', component: SearchComponent }
  ]
},
{ path: 'products',
 component: 'AnotherComponent',
 children: [
  { path: '', component: ProductsComponent },
  { path: 'compare', component: ProductComparePageComponent },
  { path: ':cat', component: CategoryComponent },
  ]
},