简体   繁体   English

单击 routerLink 到子路由角度 2 后,视图不会更改

[英]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它没有改变的原因是因为OurWorkComponentchildren

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.

相关问题 单击新路线后,组件不变 - The component doesn't change after clicking on new route 更改路线参数不会更新Angular中的视图 - Change in route param doesn't updates the view in Angular 子路由中的routerLink错误 - routerLink error in child route 注册 routerLink 不起作用 [Angular] - Sign up routerLink doesn't work [Angular] Angular 4,路由器4.0.0:routerLink或router.navigate不会以编程方式重定向到子路由 - Angular 4, Router 4.0.0: routerLink or router.navigate programatically doesn't redirect to child routes 为什么 Angular 子组件(导航栏)在路线更改后停止更新视图? - Why Angular child component ( navbar ) stops updating view after route change? Angular 2 - 应该是routerLink =“theRoute”还是[routerLink] =“[&#39;the route&#39;]”? - Angular 2 - should it be routerLink=“theRoute” or [routerLink]=“['the route']”? routerLink 在我的 angular 离子项目中不起作用 - the routerLink doesn't work in my angular ionic project 为什么角度不会在路线改变后破坏控制器$范围? - Why angular doesn't destroy controllers $scope after route was changed? Angular 子项中的 ngOnChanges 在订阅操作数据后不会触发 - Angular ngOnChanges in child doesn't trigger after subscribe manipulates data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM