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.

LocationStrategy

Enables the Location service to read route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and PathLocationStrategy.

See more...

      
      abstract class LocationStrategy {
abstract path(includeHash?: boolean): string
abstract prepareExternalUrl(internal: string): string
abstract getState(): unknown
abstract pushState(state: any, title: string, url: string, queryParams: string): void
abstract replaceState(state: any, title: string, url: string, queryParams: string): void
abstract forward(): void
abstract back(): void
historyGo(relativePosition: number)?: void
abstract onPopState(fn: LocationChangeListener): void
abstract getBaseHref(): string }

Provided in

  • 'root'

Description

Applications should use the Router or Location services to interact with application route state.

For instance, HashLocationStrategy produces URLs like http://example.com#/foo, and PathLocationStrategy produces http://example.com/foo as an equivalent URL.

See these two classes for more.

Methods

      
      abstract path(includeHash?: boolean): string
    
Parameters
includeHash boolean

Optional. Default is undefined.

Returns

string

      
      abstract prepareExternalUrl(internal: string): string
    
Parameters
internal string
Returns

string

      
      abstract getState(): unknown
    
Parameters

There are no parameters.

Returns

unknown

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

void

      
      abstract replaceState(state: any, title: string, url: string, queryParams: string): void
    
Parameters
state any
title string
url string
queryParams 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

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

void

      
      abstract getBaseHref(): string
    
Parameters

There are no parameters.

Returns

string