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

LocationStrategy

npm Package @angular/common
Module import { LocationStrategy } from '@angular/common';
Source common/src/location/location_strategy.ts

Overview

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

Description

LocationStrategy is responsible for representing and reading route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and PathLocationStrategy.

This is used under the hood of the Location service.

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.

Subclasses

Members

      
      path(includeHash?: boolean): string
    

      
      prepareExternalUrl(internal: string): string
    

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

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

      
      forward(): void
    

      
      back(): void
    

      
      onPopState(fn: LocationChangeListener): void
    

      
      getBaseHref(): string