位置等級
位置是應用程式可用於與瀏覽器的 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();
}
}