[英]View doesn't change after clicking on routerLink to child route angular 2
Hey I'm having this problem and I cant seem to figure out what is wrong, basically I have a routerLink
that goes to a child route, the url changes to the route I want but the view doesn't update to the component that is linked to the child route that is currently active嘿,我遇到了这个问题,我似乎无法弄清楚出了什么问题,基本上我有一个路由到子路由的
routerLink
,url 更改为我想要的路由,但视图没有更新到组件链接到当前活动的子路由
app.component.ts app.component.ts
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
html html
<div class="wide component">
<div class="page-wrap">
<img class="logo" src="../../assets/img/our-work-component-logo.png"><br>
<h2>Component Elite</h2>
<h3>Web portal and promotions</h3>
<p class="short-description">Lorem Ipsum</p>
<a routerLink="component" class="button orange-button">View More</a>
</div>
</div>
app.module.ts app.module.ts
import { OurWorkComponent } from './our-work/our-work.component';
import { ComponentComponent } from './our-work-content/component/component.component'
export const ROUTES: Routes = [
{ path: 'our-work', component: OurWorkComponent,
children: [
{ path: 'component', component: ComponentComponent }
]
}
];
@ngModule({
declarations: [
OurWorkComponent,
ComponentComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES)
],
providers: [],
bootstrap: [AppComponent]
})
Reason it's not changing is because of children
of OurWorkComponent
它没有改变的原因是因为
OurWorkComponent
的children
children: [
{ path: 'component', component: ComponentComponent }
]
This means there should be <router-outlet>
in OurWorkComponent
, but I can't see it, just add that in OurWorkComponent's
html
and you are good to go.这意味着
OurWorkComponent
应该有<router-outlet>
,但我看不到它,只需将其添加到OurWorkComponent's
html
中即可。
For more details please do read : https://angular.io/guide/router#nesting-routes有关更多详细信息,请阅读: https : //angular.io/guide/router#nesting-routes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.