【问题标题】:Angular2(RC-4) :Cannot read property 'pathsWithParams' of undefinedAngular2(RC-4):无法读取未定义的属性“pathsWithParams”
【发布时间】:2016-12-05 00:54:08
【问题描述】:

在 angular2 RC-4 中使用子路由时出现此错误

无法读取未定义的属性“pathsWithParams”

我的路由文件包含

export const routes: RouterConfig = [
  { path: '', component: HomeComponent },
  { path: 'demo', component: DummyComponent },
  { path: 'user-profile', component: UserProfileComponent,
    children:[
      { path: '', component: ProfileOverview },
      { path: 'smart-points', component: ProfileSmartPoints }
    ]},
]

有什么想法吗?

更新

问题实际上是每当我在 html 端使用routerLinkActive

【问题讨论】:

  • 您是否有任何代码引用该pathsWithParams 属性?
  • nop 我的路由中没有参数
  • 如果你用 plunker 重现它,我相信你可以在这样做的同时自己解决它。
  • 是的,找出问题所在:问题是每当我使用routerLinkActive

标签: angular routing


【解决方案1】:

得到答案感谢@micronyks

实际上问题是我们在使用时必须使用属性[routerLinkActiveOptions]="{exact: true}" html 中的routerLinkActive="active-link" 用于检查活动路由。

所以正确的语法是:

<a routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}" [routerLink]='["./Dummy"]'>Dummy</a>

【讨论】:

  • 我知道是因为这不是一般错误。这是something missing 错误,很难找到。但很高兴知道你明白了。
  • 是的,谢谢 :) 作为答案发布可能对其他人有益
猜你喜欢
  • 2017-12-15
  • 2017-06-18
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2017-02-06
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多