如何获取角度5中的上一页URL [英] How to get the previous page URL in angular 5

查看:58
本文介绍了如何获取角度5中的上一页URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular 5应用,我需要知道如何获取最后一个URL并将其放置为指向我的后退按钮的链接.我找到了这个location.back(),但是我需要最后一个URL作为字符串.我如何获得生成location.back()的字符串?

I'm working with Angular 5 app and I need to know how to get the last URL to place it as a link to my back button. I found this location.back() but what I need the last url as a string. How could I get the string that generates location.back()?

非常感谢!

推荐答案

Angular 6更新了用于将先前的URL作为字符串获取的代码.

Angular 6 updated code for getting previous url as string.

import { Component, OnInit } from '@angular/core';
import { Router, RoutesRecognized } from '@angular/router';
import { filter, pairwise } from 'rxjs/operators';


export class AppComponent implements OnInit {

    constructor (
        public router: Router
    ) {
    }

    ngOnInit() {
        this.router.events
            .pipe(filter((e: any) => e instanceof RoutesRecognized),
                pairwise()
            ).subscribe((e: any) => {
                console.log(e[0].urlAfterRedirects); // previous url
            });
    }

这篇关于如何获取角度5中的上一页URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆