Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page 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 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

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

Properties

Property Description
abstract href: string Read-Only
abstract protocol: string Read-Only
abstract hostname: string Read-Only
abstract port: string Read-Only
abstract pathname: string Read-Only
abstract search: string Read-Only
abstract hash: string Read-Only

Methods

      
      abstract getBaseHrefFromDOM(): string
    
Parameters

There are no parameters.

Returns

string

      
      abstract getState(): unknown
    
Parameters

There are no parameters.

Returns

unknown

Returns a function that, when executed, removes the popstate event handler.

      
      abstract onPopState(fn: LocationChangeListener): VoidFunction
    
Parameters
fn LocationChangeListener
Returns

VoidFunction

Returns a function that, when executed, removes the hashchange event handler.

      
      abstract onHashChange(fn: LocationChangeListener): VoidFunction
    
Parameters
fn LocationChangeListener
Returns

VoidFunction

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

void

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

void

      
      abstract forward(): void
    
Parameters

There are no parameters.

Returns

void

      
      abstract back(): void
    
Parameters

There are no parameters.

Returns

void

      
      historyGo(relativePosition: number)?: void
    
Parameters
relativePosition number
Returns

void