无法将相同的组件用于角度的不同路线

时间:2019-06-02 18:20:51

标签: angular routes

我有以下路线。

const routes: Routes = [ 
  {path: "", HomeComponent},
  {path: ":id", HomeComponent}
]

我无法访问第二条路线

localhost:4200/123   => error

错误:

  

错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“ / 123”   错误:无法匹配任何路线。网址段:“ / 123”

1 个答案:

答案 0 :(得分:1)

您的代码正确,请清除缓存并重新运行!

{ path: ':id', component: HomeComponent }

:)