Router
一個提供導航和操縱 URL 能力的 NgModule。
A service that provides navigation among views and URL manipulation capabilities.
class Router {
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, rootContexts: ChildrenOutletContexts, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Routes)
events: Observable<Event>
routerState: RouterState
errorHandler: ErrorHandler
malformedUriErrorHandler: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree
navigated: boolean
urlHandlingStrategy: UrlHandlingStrategy
routeReuseStrategy: RouteReuseStrategy
onSameUrlNavigation: 'reload' | 'ignore'
paramsInheritanceStrategy: 'emptyOnly' | 'always'
urlUpdateStrategy: 'deferred' | 'eager'
relativeLinkResolution: 'legacy' | 'corrected'
config: Routes
url: string
initialNavigation(): void
setUpLocationChangeListener(): void
getCurrentNavigation(): Navigation | null
resetConfig(config: Routes): void
dispose(): void
createUrlTree(commands: any[], navigationExtras: UrlCreationOptions = {}): UrlTree
navigateByUrl(url: string | UrlTree, extras: NavigationBehaviorOptions = {...}): Promise<boolean>
navigate(commands: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean>
serializeUrl(url: UrlTree): string
parseUrl(url: string): UrlTree
isActive(url: string | UrlTree, exact: boolean): boolean
}
參見
建構函式
建立路由器服務。 Creates the router service. | ||||||||||||||||||||||||
引數
|
屬性
屬性 | 說明 |
---|---|
events: Observable<Event> | 唯讀 用於表示此 NgModule 中路由事件的事件流。 An event stream for routing events in this NgModule. |
routerState: RouterState | 唯讀 此 NgModule 中路由的當前狀態。 The current state of routing in this NgModule. |
errorHandler: ErrorHandler | 本模組中的導航錯誤處理器。 A handler for navigation errors in this NgModule. |
malformedUriErrorHandler: (error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree | uri 格式無效錯誤的處理器,在 A handler for errors thrown by |
navigated: boolean | 如果為 True 則表示是否發生過至少一次導航,反之為 False。 True if at least one navigation event has occurred, false otherwise. |
urlHandlingStrategy: UrlHandlingStrategy | 提取併合並 URL。在 AngularJS 向 Angular 遷移時會用到。 A strategy for extracting and merging URLs. Used for AngularJS to Angular migrations. |
routeReuseStrategy: RouteReuseStrategy | 複用路由的策略。 A strategy for re-using routes. |
onSameUrlNavigation: 'reload' | 'ignore' | 定義當路由器收到一個導航到當前 URL 的請求時應該怎麼做。可取下列值之一: How to handle a navigation request to the current URL. One of:
|
paramsInheritanceStrategy: 'emptyOnly' | 'always' | 如何從父路由向子路由合併引數、資料和解析到的資料。可取下列值之一: How to merge parameters, data, and resolved data from parent to child routes. One of:
|
urlUpdateStrategy: 'deferred' | 'eager' | 確定路由器何時更新瀏覽器 URL。預設情況下( Determines when the router updates the browser URL. By default ( |
relativeLinkResolution: 'legacy' | 'corrected' | 啟用錯誤修復功能,以更正帶空路徑的元件中的相對連結。 Enables a bug fix that corrects relative link resolution in components with empty paths. 參見: |
config: Routes | 宣告在建構函式中 |
url: string | 唯讀 當前 URL The current URL. |
方法
設定位置變化監聽器,並執行首次導航。 Sets up the location change listener and performs the initial navigation. |
引數沒有引數。 返回值
|
設定 location 更改監聽器。該監聽器檢測從路由器外部觸發的導航(例如,瀏覽器的後退/前進按鈕),並安排相應的路由器導航,以便觸發正確的事件、守衛等。 Sets up the location change listener. This listener detects navigations triggered from outside the Router (the browser back/forward buttons, for example) and schedules a corresponding Router navigation so that the correct events, guards, etc. are triggered. |
引數沒有引數。 返回值
|
當前導航物件(如果存在) The current Navigation object if one exists |
重置供導航和產生連結使用的配置項。 Resets the route configuration used for navigation and generating links. |
使用說明
|
銷燬路由器 Disposes of the router. |
引數沒有引數。 返回值
|
將 URL 段新增到當前 URL 樹中以建立新的 URL 樹。 Appends URL segments to the current URL tree to create a new URL tree. | ||||||
引數
返回值新的 URL Tree。
| ||||||
使用說明
|
基於所提供的 URL 進行導航,必須使用絕對路徑。 Navigates to a view using an absolute route path. See also: | ||||||
引數
返回值一個 Promise,當導航成功時,它會解析成
| ||||||
使用說明以下呼叫要求導航到絕對路徑。 The following calls request navigation to an absolute path.
|
基於所提供的命令陣列和起點路由進行導航。 如果沒有指定起點路由,則從根路由開始進行絕對導航。 Navigate based on the provided array of commands and a starting point. If no starting route is provided, the navigation is absolute. See also: | ||||||
引數
返回值一個 Promise,在導航成功時解析為
| ||||||
使用說明以下呼叫請求導航到相對於當前 URL 的動態路由路徑。 The following calls request navigation to a dynamic route path relative to the current URL.
|
把 Serializes a |
把字串解析為 Parses a string into a |
返回指定的 Returns whether the url is activated |