填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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