Angular路由中保留URL参数:解决<router-outlet (activate)='reuseTab.activate($event)'>切换Tab页参数消失问题
""该错误是因为在定义路由时使用了一个不支持的属性"queryParamsHandling"。在Angular中,路由的定义是一个Route对象,不支持"queryParamsHandling"属性。\n\n要解决这个问题,你可以使用另一种方式来处理路由参数不消失的问题。你可以在路由定义中使用queryParams属性来传递参数,并在组件中使用ActivatedRoute来获取参数。\n\n首先,你需要在路由定义中将参数作为queryParams传递。例如:\n\n\n{ path: 'update', component: UpdateComponent, data: { title: 'Update', reuse: true } }\n\n\n然后,在组件中使用ActivatedRoute来获取参数。例如:\n\ntypescript\nimport { Component, OnInit } from '@angular/core';\nimport { ActivatedRoute, Params } from '@angular/router';\n\n@Component({\n selector: 'app-update',\n templateUrl: './update.component.html',\n styleUrls: ['./update.component.css']\n})\nexport class UpdateComponent implements OnInit {\n queryParams: Params;\n\n constructor(private route: ActivatedRoute) {}\n\n ngOnInit() {\n this.route.queryParams.subscribe(params => {\n this.queryParams = params;\n // 处理参数\n });\n }\n}\n\n\n现在,你可以在UpdateComponent组件中使用this.queryParams来访问路由参数,并在切换tab页时保留参数。\n\n希望对你有帮助!"\
原文地址: https://www.cveoy.top/t/topic/pxYP 著作权归作者所有。请勿转载和采集!