angular6 - 如何以角度传递额外的路由参数?
问题描述
我正在开发 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}});
}
解决方案
更改导航()
this.router.navigate(['/survey', this.listedSurvey.surveyIdNum]);
推荐阅读
- arrays - 如何从 golang 中的数组 unsafe.Pointer 创建数组或切片?
- c++ - 可以在 C++11 中模拟 std::is_invocable 吗?
- python - 字符串匹配的向量化
- vba - 检查是否存在隐藏的工作表
- jmeter - JMeter写入文件脚本正在复制打印
- fiware - Authzforce 权限创建问题
- java - Log4j2 以编程方式添加 asyncLogger
- java - 来自 Tomcat 中 REST Web 应用程序的奇怪响应文本编码
- python - python list.append 弄乱了数字的小数位
- angular - 将 ng-content 元素的宽度设置为通过的子元素的大小