import { Component, OnInit } from '@angular/core';
import { PlatformLocation } from '@angular/common';

@Component({
selector: 'app-first',
templateUrl: './first.component.html',
styleUrls: ['./first.component.scss']
})
export class FirstComponent implements OnInit {

constructor(public location: PlatformLocation) { }

ngOnInit() {

console.log(this.location);
console.log(this.location.hash);// "#id=1"
console.log(this.location.hostname);// "localhost"
console.log(this.location.href);// "http://localhost:4200/first#id=1"
console.log(this.location.pathname);// "/first"
console.log(this.location.port);// "4200"
console.log(this.location.protocol);// "http:"

}
}

Angular获取Location对象,获取当前网页url、hash、hostname、href、pathname、port、protocal_location