[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/common/PlatformLocation [Back]  [Original]

PlatformLocation Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/common

PlatformLocation

Class
stable

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

On this page

    arrow_upward_alt Back to the top

    API

        
          abstract class PlatformLocation {  abstract getBaseHrefFromDOM(): string;  abstract getState(): unknown;  abstract onPopState(fn: LocationChangeListener): VoidFunction;  abstract onHashChange(fn: LocationChangeListener): VoidFunction;  abstract readonly href: string;  abstract readonly protocol: string;  abstract readonly hostname: string;  abstract readonly port: string;  abstract readonly pathname: string;  abstract readonly search: string;  abstract readonly hash: string;  abstract replaceState(state: any, title: string, url: string): void;  abstract pushState(state: any, title: string, url: string): void;  abstract forward(): void;  abstract back(): void;  optional historyGo(relativePosition: number): void;}
        
        

    getBaseHrefFromDOM

    string
    @returnsstring

    getState

    unknown
    @returnsunknown

    onPopState

    VoidFunction

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

    @returnsVoidFunction

    onHashChange

    VoidFunction

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

    @returnsVoidFunction

    href

    string

    protocol

    string

    hostname

    string

    port

    string

    pathname

    string

    hash

    string

    replaceState

    void
    @paramstateany
    @paramtitlestring
    @paramurlstring
    @returnsvoid

    pushState

    void
    @paramstateany
    @paramtitlestring
    @paramurlstring
    @returnsvoid

    forward

    void
    @returnsvoid

    back

    void
    @returnsvoid

    historyGo

    void
    @paramrelativePositionnumber
    @returnsvoid

    Description

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

    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.

    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page