javascript - View doesn't change after clicking on routerLink to child route angular 2 - Stack Overflow

Hey I'm having this problem and I cant seem to figure out what is wrong, basically I have a router

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 ponent that is linked to the child route that is currently active

appponent.ts

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>

html

<div class="wide ponent">
    <div class="page-wrap">
        <img class="logo" src="../../assets/img/our-work-ponent-logo.png"><br>
        <h2>Component Elite</h2>
        <h3>Web portal and promotions</h3>

        <p class="short-description">Lorem Ipsum</p>
        <a routerLink="ponent" class="button orange-button">View More</a>
    </div>
</div>

app.module.ts

import { OurWorkComponent } from './our-work/our-workponent';
import { ComponentComponent } from './our-work-content/ponent/ponentponent'

export const ROUTES: Routes = [
  { path: 'our-work', ponent: OurWorkComponent,
      children: [
         { path: 'ponent', ponent: ComponentComponent }
      ]
  }
];

@ngModule({
  declarations: [
     OurWorkComponent,
     ComponentComponent
  ],
  imports: [
     BrowserModule,
     RouterModule.forRoot(ROUTES)
  ],
  providers: [],
  bootstrap: [AppComponent]
})

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 ponent that is linked to the child route that is currently active

app.ponent.ts

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>

html

<div class="wide ponent">
    <div class="page-wrap">
        <img class="logo" src="../../assets/img/our-work-ponent-logo.png"><br>
        <h2>Component Elite</h2>
        <h3>Web portal and promotions</h3>

        <p class="short-description">Lorem Ipsum</p>
        <a routerLink="ponent" class="button orange-button">View More</a>
    </div>
</div>

app.module.ts

import { OurWorkComponent } from './our-work/our-work.ponent';
import { ComponentComponent } from './our-work-content/ponent/ponent.ponent'

export const ROUTES: Routes = [
  { path: 'our-work', ponent: OurWorkComponent,
      children: [
         { path: 'ponent', ponent: ComponentComponent }
      ]
  }
];

@ngModule({
  declarations: [
     OurWorkComponent,
     ComponentComponent
  ],
  imports: [
     BrowserModule,
     RouterModule.forRoot(ROUTES)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
Share Improve this question edited Dec 7, 2017 at 4:31 artgb 3,2536 gold badges20 silver badges40 bronze badges asked Dec 7, 2017 at 3:49 Smokey DawsonSmokey Dawson 9,24023 gold badges85 silver badges162 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Reason it's not changing is because of children of OurWorkComponent

children: [
    { path: 'ponent', ponent: 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.


For more details please do read : https://angular.io/guide/router#nesting-routes

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745195261a4616056.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信