Angular RouterLink无法正常工作
我有一个与RouterLink一起工作的应用程序 以下是应用程序模块中的导入数组:Angular RouterLink无法正常工作,angular,routerlink,Angular,Routerlink,我有一个与RouterLink一起工作的应用程序 以下是应用程序模块中的导入数组: imports: [ BrowserModule, RouterModule.forRoot([ {path: '', component: HomeComponent}, {path:'contact', component: ContactComponent}, {path: 'about/:id/:name', component: AboutCompon
imports: [
BrowserModule,
RouterModule.forRoot([
{path: '', component: HomeComponent},
{path:'contact', component: ContactComponent},
{path: 'about/:id/:name', component: AboutComponent}
])
这是app.component.html:
<div>
<a routerLink="" routerLinkActive="active">Home</a>
<a routerLink="/contact" routerLinkActive="active"> Contact</a>
</div>
<router-outlet></router-outlet>
家
接触
在主页上如果用户单击关于该用户的,,则应将其重定向到特定用户的关于页面:
<div>
<a [routerLink]="['/about', follower.id, follower.name]">About this user { ... </a>
</div>
关于此用户{。。。
但是,当应用程序加载时,我在控制台上遇到以下错误:
无法读取未定义的属性“id”
您能帮我找出哪里出了问题吗?使用安全导航操作器,如下所示:
<a [routerLink]="['/about', follower?.id, follower?.name]">About this user { ... </a>
关于此用户{。。。
使用安全导航操作器,如下所示:
<a [routerLink]="['/about', follower?.id, follower?.name]">About this user { ... </a>
关于此用户{。。。
使用如下操作符检查对象键是否存在:
<div>
<a [routerLink]="['/about', follower?.id, follower?.name]">About this user { ... </a>
</div>
关于此用户{。。。
使用如下操作符检查对象键是否存在:
<div>
<a [routerLink]="['/about', follower?.id, follower?.name]">About this user { ... </a>
</div>
关于此用户{。。。