PlatformLocation
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): void
abstract onHashChange(fn: LocationChangeListener): void
abstract replaceState(state: any, title: string, url: string): void
abstract pushState(state: any, title: string, url: string): void
abstract forward(): void
abstract back(): void
}
说明
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.
The PlatformLocation
class is used directly by all implementations of LocationStrategy
when they need to interact with the DOM APIs like pushState, popState, etc.
LocationStrategy
in turn is used by the Location
service which is used directly by the Router
in order to navigate between routes. Since all interactions between Router
/ Location
/ LocationStrategy
and DOM APIs flow through the PlatformLocation
class, they are all platform-agnostic.
属性
属性 | 说明 |
---|---|
abstract href: string | 只读 |
abstract protocol: string | 只读 |
abstract hostname: string | 只读 |
abstract port: string | 只读 |
abstract pathname: string | 只读 |
abstract search: string | 只读 |
abstract hash: string | 只读 |
方法
参数没有参数。 返回值
|
参数没有参数。 返回值
|
参数
返回值
|
参数
返回值
|
参数没有参数。 返回值
|
参数没有参数。 返回值
|