填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

PlatformLocation

此類別不應由應用程式開發人員直接使用。而應使用 Location

This class should not be used directly by an application developer. Instead, use Location.

檢視"說明"...

      
      abstract class PlatformLocation {
  abstract href: string
  abstract protocol: string
  abstract hostname: string
  abstract port: string
  abstract pathname: string
  abstract search: string
  abstract hash: string
  abstract getBaseHrefFromDOM(): string
  abstract getState(): unknown
  abstract onPopState(fn: LocationChangeListener): VoidFunction
  abstract onHashChange(fn: LocationChangeListener): VoidFunction
  abstract replaceState(state: any, title: string, url: string): void
  abstract pushState(state: any, title: string, url: string): void
  abstract forward(): void
  abstract back(): void
  historyGo(relativePosition: number)?: void
}
    

Provided in

  •       
          'platform'
        

說明

PlatformLocation 封裝了對 DOM API 的所有呼叫,這可以讓路由器與平臺無關。這意味著我們可以為 Angular 支援的不同平臺提供 PlatformLocation 的不同實現。例如, @angular/platform-browser 提供了特定於瀏覽器環境的實現,而 @angular/platform-server 提供了適合與伺服器端渲染一起使用的實現。

PlatformLocation encapsulates all calls to DOM APIs, which allows the Router to be platform-agnostic. This means that we can have different implementation of PlatformLocation for the different platforms that Angular supports. For example, @angular/platform-browser provides an implementation specific to the browser environment, while @angular/platform-server provides one suitable for use with server-side rendering.

的所有實現在需要與 DOM API(例如 pushState,popState 等)進行互動時,都直接使用 PlatformLocation

The PlatformLocation class is used directly by all implementations of LocationStrategywhen they need to interact with the DOM APIs like pushState, popState, etc.

LocationStrategyLocationStrategy

Router直接使用的 Location服務使用,以便在路由之間導航。由於 Router/ Location/ LocationStrategy與 DOM API 之間的所有互動都是透過 PlatformLocation 類別進行的,因此它們都是與平臺無關的。

in turn is used by the Locationservice which is used directly by the Routerin order to navigate between routes. Since all interactions between Router/ Location/ LocationStrategyand DOM APIs flow through the PlatformLocation class, they are all platform-agnostic.

LocationStrategy

屬性

屬性說明
abstract href: string唯讀
abstract protocol: string唯讀
abstract hostname: string唯讀
abstract port: string唯讀
abstract pathname: string唯讀
abstract search: string唯讀
abstract hash: string唯讀

方法

      
      abstract getBaseHrefFromDOM(): string
    
引數

沒有引數。

返回值

string

      
      abstract getState(): unknown
    
引數

沒有引數。

返回值

unknown

Returns a function that, when executed, removes the popstate event handler.

      
      abstract onPopState(fn: LocationChangeListener): VoidFunction
    
引數
fn LocationChangeListener
返回值

VoidFunction

Returns a function that, when executed, removes the hashchange event handler.

      
      abstract onHashChange(fn: LocationChangeListener): VoidFunction
    
引數
fn LocationChangeListener
返回值

VoidFunction

      
      abstract replaceState(state: any, title: string, url: string): void
    
引數
state any
title string
url string
返回值

void

      
      abstract pushState(state: any, title: string, url: string): void
    
引數
state any
title string
url string
返回值

void

      
      abstract forward(): void
    
引數

沒有引數。

返回值

void

      
      abstract back(): void
    
引數

沒有引數。

返回值

void

      
      historyGo(relativePosition: number)?: void
    
引數
relativePosition number
返回值

void