我有以下组件结构:
AppComponent
--NetworkComponent
----HeaderComponent
----HomeComponent
------SideProfileComponent
------FeedComponent
----ProfileComponent
我正试图从SideProfileComponent
导航到ProfileComponent
使用routerLink
如下:
<a [routerLink]="['/user', user.username]">
<div class="name">{{ user.firstname }} {{user.lastname}}</div>
<div>@{{ user.username }}</div>
</a>
当我这样做时,页面确实导航到所需的组件,但在控制台中,抛出以下错误
当我在HomeComponent
(加载了SideProfileComponent
时)并使用HeaderComponent
上的链接导航到ProfileComponent
时,错误就不会出现了!
导致错误的问题是什么?未捕获的TypeError:无法读取属性&#39; parentNode&#39;是出现?
应用-routing.module.ts
const appRoutes: Routes = [
{
path: '',
component: NetworkComponent,
canActivate: [NetworkAuthGuard],
children: [
{
path: '',
component: NetworkHomeComponent,
pathMatch: 'full'
},
{
path: 'user/:username',
component: NetworkProfileComponent
},
]
},
{
path: 'login',
component: LoginComponent
},
{
path: '**',
redirectTo: ''
},
]
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}