位置等级
位置是应用程序可用于与浏览器的 URL 进行交互的服务。根据使用的 LocationStrategy,Location 将持久保存到 URL 的路径或 URL 的哈希段。
Location 负责根据应用程序的基本 href 规范化 URL。
import {Component} from '@angular/core';
import {Location} from '@angular/common';
@Component({
selector: 'app-component'
})
class AppCmp {
constructor(_location: Location) {
//Changes the browsers URL to the normalized version of the given URL,
//and pushes a new item onto the platform's history.
_location.go('/foo');
}
backClicked() {
//Navigates back in the platform's history.
this._location.back();
}
forwardClicked() {
//Navigates forward in the platform's history.
this._location.back();
}
}