LocationStrategy

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

查看"说明"...

      
      abstract class LocationStrategy {
  abstract path(includeHash?: boolean): string
  abstract prepareExternalUrl(internal: string): string
  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
  abstract onPopState(fn: LocationChangeListener): void
  abstract getBaseHref(): string
}
    

说明

This is used under the hood of the Locationservice.

Applications should use the Routeror Locationservices to interact with application route state.

For instance, HashLocationStrategyproduces URLs like http://example.com#/foo, and PathLocationStrategyproduces http://example.com/foo as an equivalent URL.

See these two classes for more.

方法

abstract path(includeHash?: boolean): string
      
      abstract path(includeHash?: boolean): string
    
参数
includeHash boolean

可选. 默认值是 undefined.

返回值

string

abstract prepareExternalUrl(internal: string): string
      
      abstract prepareExternalUrl(internal: string): string
    
参数
internal string
返回值

string

abstract pushState(state: any, title: string, url: string, queryParams: string): void
      
      abstract pushState(state: any, title: string, url: string, queryParams: string): void
    
参数
state any
title string
url string
queryParams string
返回值

void

abstract replaceState(state: any, title: string, url: string, queryParams: string): void
      
      abstract replaceState(state: any, title: string, url: string, queryParams: string): void
    
参数
state any
title string
url string
queryParams string
返回值

void

abstract forward(): void
      
      abstract forward(): void
    
参数

没有参数。

返回值

void

abstract back(): void
      
      abstract back(): void
    
参数

没有参数。

返回值

void

abstract onPopState(fn: LocationChangeListener): void
      
      abstract onPopState(fn: LocationChangeListener): void
    
参数
fn LocationChangeListener
返回值

void

abstract getBaseHref(): string
      
      abstract getBaseHref(): string
    
参数

没有参数。

返回值

string