使用Angular Router导航到Parent的兄弟姐妹时出错

时间:2017-12-10 16:10:17

标签: javascript angular angular-router

我有以下组件结构:

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>

当我这样做时,页面确实导航到所需的组件,但在控制台中,抛出以下错误

enter image description here 当我在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 {

}

0 个答案:

没有答案