Angular 7路由器 - 是否有一种方法可以弹出顶部路线



我的应用程序中有一个bootstrap -modal,并希望在打开时反映在浏览历史记录上,因此当用户单击浏览器的返回按钮时,模态将关闭。

我熟悉Angular的Location对象,因此Location.back()Location.go()适合我的场景。

问题是 - 一旦用户单击"后退"按钮,我想从浏览器历史记录中弹出顶部路径,因此关闭模式后 - 用户无法使用浏览器的"下一个"按钮重新打开它。<<<<<<<<<<<<<<<<<</p>

有什么方法可以使用Angular的路由器/位置/任何其他Angular-ish方式?

这是我用来实现此目标的方法。每当用户单击"标头组件"按钮称为"发布"时,它将显示一个模态对话框。当用户单击"后退"按钮时,它将用户进入上一个路由。这是我的服务处理对话框的开放:

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { PostItDialog } from './post-it-dialog.component';
import { Location } from '@angular/common';
import { MatDialog } from '@angular/material/dialog';`
    public openPostItDialog(dialog: MatDialog): void {
        const dialogRef = dialog.open(PostItDialog, {
          width: '350px'
        });
        const url = this.router.createUrlTree(['posts/new']).toString();
        this.location.go(url);
        console.log("Dialog was open");
    
        dialogRef.afterClosed().subscribe(() => {
          console.log("The dialog was closed");
          this.location.go("");
        })

相关内容

最新更新