简体   繁体   English

为什么 Angular router.navigate 不导航?

[英]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.我想导航一个子根,但在 1 次导航后 url 更改但组件未加载,但如果我刷新 url 组件正在加载。 If I am in the navigated root, url change but not load, if I am not on the navigated root it is loading.如果我在导航根目录中,则 url 更改但未加载,如果我不在导航根目录中,则正在加载。

the links..链接..

http://localhost:4000/project-details/16/project-details http://localhost:4000/project-details/16/project-details
http://localhost:4000/project-details/21/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项目详细信息.component

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

app.routers.ts 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();
        });
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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