簡體   English   中英

為什么 Angular router.navigate 不導航?

[英]Why Angular router.navigate not navigating?

我想導航一個子根,但在 1 次導航后 url 更改但組件未加載,但如果我刷新 url 組件正在加載。 如果我在導航根目錄中,則 url 更改但未加載,如果我不在導航根目錄中,則正在加載。

鏈接..

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]);
    }

項目詳細信息.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",
       }
...

我找到了一個解決方案:

//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