This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

PlatformLocation

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

See more...

      
      abstract class PlatformLocation {
  abstract pathname: string
  abstract search: string
  abstract 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
}
    

Description

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

Properties

Property Description
abstract pathname: string Read-only.
abstract search: string Read-only.
abstract hash: string Read-only.

Methods

abstract getBaseHrefFromDOM(): string
      
      abstract getBaseHrefFromDOM(): string
    

Parameters

There are no parameters.

Returns

string

abstract onPopState(fn: LocationChangeListener): void
      
      abstract onPopState(fn: LocationChangeListener): void
    

Parameters

fn

Type: LocationChangeListener.

Returns

void

abstract onHashChange(fn: LocationChangeListener): void
      
      abstract onHashChange(fn: LocationChangeListener): void
    

Parameters

fn

Type: LocationChangeListener.

Returns

void

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

Parameters

state

Type: any.

title

Type: string.

url

Type: string.

Returns

void

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

Parameters

state

Type: any.

title

Type: string.

url

Type: string.

Returns

void

abstract forward(): void
      
      abstract forward(): void
    

Parameters

There are no parameters.

Returns

void

abstract back(): void
      
      abstract back(): void
    

Parameters

There are no parameters.

Returns

void