代码之家  ›  专栏  ›  技术社区  ›  K.Z

如何以角度传递额外的路由参数?

  •  0
  • K.Z  · 技术社区  · 6 年前

     this.router.navigate(['/survey'], this.listedSurvey.surveyIdNum);
    

    但我相信我错过了一些东西,因为我无法做到这一点。

    应用程序路径

    const routes: Routes = [
    { path:'welcome', component:WelcomeComponent },
    { path:'', redirectTo: 'welcome', pathMatch:'full'},
    { path:'survey', loadChildren: '../survey/survey.module#SurveyModule' },
    { path:'**', component:PageNotFoundComponent}
    ];
    
    @NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [
     RouterModule
     ]
     })
    
     export class AppRoutingModule { }
    

    const routes: Routes = [
    { 
        path:'', 
        component:SurveyComponent,
    },
    {
        path:':id',
        component: SurveyFormComponent
     }
    ];
    
    @NgModule({
     imports:[
         RouterModule.forChild(routes)
     ],
     exports:[]
    })
     export class SurveyRouting{
    }
    

    组成部分

     private handleSelectedSurvey(dataItem:any){
       this.listedSurvey = dataItem;
       const a:number = 2;
       //this.router.navigate(['/survey'], this.listedSurvey.surveyIdNum);
       this.router.navigate(['/survey'],{queryParams:{id:a}}); 
     }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Ininiv    6 年前

    更改导航() this.router.navigate(['/survey', this.listedSurvey.surveyIdNum]);

    参考: https://angular.io/api/router/Router#navigate

    推荐文章