angular - Angular - 获取当前激活的路线并使用不同的路线参数重新导航到同一页面
问题描述
在更改标题中搜索文本框中的 itemCode 后,我试图获取当前路线并导航到同一路线。当我最初来到页面时,父路由是“iauth/iauthedit/1706”,然后用户导航到子路由“/info”,还有其他几条用户可以从侧面导航栏导航的路线,如下图所示. 如图所示,当我将应用程序标头中的项目代码更改为 1853 时,URL 应更改为“iauth/iauthedit/1853/info”,如何根据当前路由 URL 动态更改浏览器 URL 路由参数浏览器?,我正在尝试从浏览器 URL 中找到当前场景父级“iauth/iauthedit/”中的当前激活路由,以便进行导航
this.router.navigate(['iauth/iauthedit/', 1853];
以下是目前的路线:
const itemAuthRoutes: Routes = [
{
path: 'iauthedit/:itemCode',
children: [
{
path: '',
canActivate: [AuthGuard],
//data: { feature: AppFeature.AuthorizedItem },
component: ItemAuthorizationEditComponent,
children: [
{
path: 'info', component: ItemAuthorizationInfoEditComponent
}]
}]
}]
解决方案
您可以尝试遍历routeConfig
'spath
属性
constructor(private activatedRoute: ActivatedRoute, private router: Router) {}
navigate(newId: string) {
let route = this.activatedRoute.snapshot;
const parts = [];
while (route) {
route.routeConfig && route.routeConfig.path && parts.push(route.routeConfig.path);
route = route.parent;
}
// `parts` now contain your route's pieces - do whatever you deem fit with that
parts[1] = newId; // i.e. replace the part that needs replacing
this.router.navigate(parts.reverse());
}
希望这有所帮助 :-)
推荐阅读
- python - importError pdfkit 与 docker 要求 wkhtmltopdf
- python - 如何将 json 值传递给 highchart 热图
- html - Angular,如何为 iframe 源使用变量?
- python - 导致未处理错误的子进程错误
- excel - 如何以 $A$1 形式获取单元格的地址
- powershell - 如何从 Diagnostics-Performance 获取启动时间
- google-cloud-platform - 将 Filestack 与 GCP 存储桶集成是否需要 GCP 服务帐户的项目所有者角色?
- reactjs - 不可变的删除对象条目反应减速器
- mysql - 如何从 MySQL 中的变量中添加具有默认值的列?
- c# - 正则表达式替换 (C#)