简体   繁体   中英

Why Angular router.navigate not navigating?

I want to navigate a child root but after 1 navigation the url changing but the component is not load, but if I refresh the url the component is loading. If I am in the navigated root, url change but not load, if I am not on the navigated root it is loading.

the links..

http://localhost:4000/project-details/16/project-details
http://localhost:4000/project-details/21/project-details

//when select an option navigate to project-details/id
   goToProjectDetails(projectId: any) {
        this.router.navigate(['project-details', projectId]);
    }

project-details.component

 ngOnInit() {
       this.subscription = this.route.params.subscribe(() => {
           this.getProject();
           this.tableRender();
       });
   }

app.routers.ts

{
       path: "project-details/:id",
       children: [
           {
               path:'',
               redirectTo: 'project-details',
               pathMatch: 'full'
           },
           { path: 'project-details', component: ProjectDetailsComponent },
           { path: 'translation', component: TranslationComponent  },
           { path: 'env', component: EnvVariablesComponent },
           { path: 'urls', component: UrlsComponent },
           ]
       ,
       component: ProjectDetailsMenuComponent,
       data: {
           id: "project.details",
       }
...

I found a solution:

//private state: StateService
    ngOnInit() {
        this.subscription = this.state.subscribeImmediately(() => {
            this.getProject();
            this.tableRender();
        });
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM