AngularDialog打开后会导致新加载的页面丢失查询参数。
创始人
2024-10-24 12:01:10
0

在打开对话框时,手动保存当前查询参数并将其添加到对话框URL中,以便在关闭对话框时重新加载原始页面时恢复查询参数。

示例代码:

import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { MatDialog } from '@angular/material/dialog'; import { MyDialogComponent } from './my-dialog/my-dialog.component';

@Component({ selector: 'app-my-page', templateUrl: './my-page.component.html', styleUrls: ['./my-page.component.css'] }) export class MyPageComponent implements OnInit {

constructor(private route: ActivatedRoute, private router: Router, private dialog: MatDialog) { }

ngOnInit() { this.route.queryParams.subscribe(params => { // Do something with the query params }); }

openDialog() { // Save current query params const queryParams = { ...this.route.snapshot.queryParams };

// Open the dialog with updated URL including query params
const dialogRef = this.dialog.open(MyDialogComponent, {
  width: '400px',
  data: {},
  // Append current query params to dialog URL
  queryParams: queryParams 
});

dialogRef.afterClosed().subscribe(result => {
  // Reload page with original query params
  this.router.navigate([], {
    relativeTo: this.route,
    queryParams: queryParams
  });
});

}

}

相关内容

热门资讯

透视有挂!红龙poker透视,... 透视有挂!红龙poker透视,hhpoker真的有透视吗,软件教程(起初是有挂);大神普及一款德州a...
透视ai代打!德普之星app安... 透视ai代打!德普之星app安卓版破解版,德普之星有辅助软件吗,普及教程(固有有挂);德普之星app...
辅助透视!wpk脚本辅助器,w... 辅助透视!wpk脚本辅助器,wepoker软件靠谱么,爆料教程(起初有挂)关于wpk脚本辅助器的基本...
透视新版!aapoker辅助插... 透视新版!aapoker辅助插件工具,来玩app破解版,曝光教程(本然是有挂);aapoker辅助插...
透视最新!aapoker辅助挂... 透视最新!aapoker辅助挂,hhpoker辅助挂下载,我来教教你(固有有挂)1、许多玩家不知道a...
透视透视!智星菠萝辅助器,we... 透视透视!智星菠萝辅助器,wepoker游戏下载,插件教程(其实是真的有挂);超受欢迎的智星菠萝辅助...
透视系统!德普之星透视辅助,w... 透视系统!德普之星透视辅助,wpk插件,安装教程(起初真的有挂);是一款可以让一直输的玩家,快速成为...
透视苹果版!aapoker辅助... 透视苹果版!aapoker辅助器怎么用,wepoker透视app下载,透视教程(原生真的是有挂)1、...
透视好友!hhpoker透视脚... 透视好友!hhpoker透视脚本视频,德州辅助工具到底怎么样,必备教程(往昔真的是有挂);(需添加指...
透视存在!wepoker透视脚... 透视存在!wepoker透视脚本免费,pokemmo脚本手机版,透明挂教程(确实是真的有挂);wep...