填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

LocationStrategy

使 Location 服务能够从浏览器的 URL 读取路由状态。 Angular 提供了两种策略: HashLocationStrategyPathLocationStrategy

Enables the Location service to read route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and 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
  historyGo(relativePosition: number)?: void
  abstract onPopState(fn: LocationChangeListener): void
  abstract getBaseHref(): string
}
    

Provided in

说明

应用程序应使用 RouterLocation 服务与应用程序的路由状态进行交互。

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

例如,HashLocationStrategy 会处理像 http://example.com#/foo 这样的 URL,而 PathLocationStrategy 会处理像 http://example.com/foo 这样的等价 URL。

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.

方法

      
      abstract path(includeHash?: boolean): string
    
参数
includeHash boolean
可选. 默认值是 `undefined`.
返回值

string

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

string

      
      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
    
参数
state any
title string
url string
queryParams string
返回值

void

      
      abstract forward(): void
    
参数

没有参数。

返回值

void

      
      abstract back(): void
    
参数

没有参数。

返回值

void

      
      historyGo(relativePosition: number)?: void
    
参数
relativePosition number
返回值

void

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

void

      
      abstract getBaseHref(): string
    
参数

没有参数。

返回值

string