angular 5 routing on same component is not working

Discussão em 'Angular' iniciado por Krish, Janeiro 17, 2025.

  1. Krish

    Krish Guest

    I am trying to route the same path the second time, but it's not invoking into ngOnInit() to load the new data on the same component.

    app.routing.module.ts:

    const routes: Routes = [
    {path: '', component: mycomponet}
    {path: 'name', component: nameComponent}
    ]
    @NGModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
    })


    app.service.ts: were my routing logic is placed and I am trying to navigate the nameComponent again

    let newData = []
    nextClick(data) {
    let condition = true;
    let newData = [];
    if(condition == true) {
    this.router.naviagete(['app-name/name'])
    }
    return this.newData
    }


    name.component.ts

    ngOnInit() {
    console.log(this.appService.nextClick())
    }


    here my name.component ngOnInit() invoking the first time, but when I try to route the same path again it's not invoking. how to navigate the same path with different data (newData)?

    Continue reading...

Compartilhe esta Página