PlatformLocation
此类不应由应用程序开发人员直接使用。而应使用 Location。
This class should not be used directly by an application developer. Instead, use Location.
abstract class PlatformLocation {
abstract href: string
abstract protocol: string
abstract hostname: string
abstract port: string
abstract pathname: string
abstract search: string
abstract hash: string
abstract getBaseHrefFromDOM(): string
abstract getState(): unknown
abstract onPopState(fn: LocationChangeListener): VoidFunction
abstract onHashChange(fn: LocationChangeListener): VoidFunction
abstract replaceState(state: any, title: string, url: string): void
abstract pushState(state: any, title: string, url: string): void
abstract forward(): void
abstract back(): void
historyGo(relativePosition: number)?: void
}
Provided in
'platform'
说明
PlatformLocation 封装了对 DOM API 的所有调用,这可以让路由器与平台无关。这意味着我们可以为 Angular 支持的不同平台提供 PlatformLocation 的不同实现。例如, @angular/platform-browser 提供了特定于浏览器环境的实现,而 @angular/platform-server 提供了适合与服务器端渲染一起使用的实现。
PlatformLocation encapsulates all calls to DOM APIs, which allows the Router to be platform-agnostic. This means that we can have different implementation of PlatformLocation for the different platforms that Angular supports. For example, @angular/platform-browser provides an implementation specific to the browser environment, while @angular/platform-server provides one suitable for use with server-side rendering.
的所有实现在需要与 DOM API(例如 pushState,popState 等)进行交互时,都直接使用 PlatformLocation
The PlatformLocation class is used directly by all implementations of LocationStrategywhen they need to interact with the DOM APIs like pushState, popState, etc.
LocationStrategyLocationStrategy由 Router直接使用的 Location服务使用,以便在路由之间导航。由于 Router/ Location/ LocationStrategy与 DOM API 之间的所有交互都是通过 PlatformLocation 类进行的,因此它们都是与平台无关的。
in turn is used by the Locationservice which is used directly by the Routerin order to navigate between routes. Since all interactions between Router/ Location/ LocationStrategyand DOM APIs flow through the PlatformLocation class, they are all platform-agnostic.
LocationStrategy属性
| 属性 | 说明 |
|---|---|
abstract href: string | 只读 |
abstract protocol: string | 只读 |
abstract hostname: string | 只读 |
abstract port: string | 只读 |
abstract pathname: string | 只读 |
abstract search: string | 只读 |
abstract hash: string | 只读 |
方法
参数没有参数。 返回值
|
参数没有参数。 返回值
|
Returns a function that, when executed, removes the | |||
参数
返回值
|
Returns a function that, when executed, removes the | |||
参数
返回值
|
参数没有参数。 返回值
|
参数没有参数。 返回值
|