首页 > 解决方案 > 如何以角度传递额外的路由参数?

问题描述

我正在开发 Angular 6 应用程序,并在应用程序根级别配置路由调查,然后使用 :id 获取调查详细信息页面,我正在尝试使用从组件导航

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

标签: angular6angular-routing

解决方案


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

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


推荐阅读