PlatformLocation

This class should not be used directly by an application developer. Instead, use Location.

abstract class PlatformLocation { abstract get pathname: string abstract get search: string abstract get hash: string abstract getBaseHrefFromDOM(): string 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-webworker provides one suitable for use with web workers.

The PlatformLocation class is used directly by all implementations of LocationStrategywhen they need to interact with the DOM apis like pushState, popState, etc...

LocationStrategy

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 independent.

属性

属性名类型说明
pathname只读
search只读
hash只读

方法

abstract getBaseHrefFromDOM(): string

参数

没有参数。

返回值

string

abstract onPopState(fn: LocationChangeListener): void

参数

fn

Type: LocationChangeListener.

返回值

void

abstract onHashChange(fn: LocationChangeListener): void

参数

fn

Type: LocationChangeListener.

返回值

void

abstract replaceState(state: any, title: string, url: string): void

参数

state

Type: any.

title

Type: string.

url

Type: string.

返回值

void

abstract pushState(state: any, title: string, url: string): void

参数

state

Type: any.

title

Type: string.

url

Type: string.

返回值

void

abstract forward(): void

参数

没有参数。

返回值

void

abstract back(): void

参数

没有参数。

返回值

void