填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写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