如何在角度传递附加路线参数?

时间:2019-02-05 09:43:47

标签: angular6 angular-routing

我正在使用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}}); 
 }

1 个答案:

答案 0 :(得分:1)

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

引用:https://angular.io/api/router/Router#navigate