Router
一个提供导航和操纵 URL 能力的 NgModule。
A service that provides navigation and URL manipulation capabilities.
class Router {
constructor(rootComponentType: Type<any>, urlSerializer: UrlSerializer, rootContexts: ChildrenOutletContexts, location: Location, injector: Injector, loader: NgModuleFactoryLoader, compiler: Compiler, config: Route[])
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: Route[]): void
ngOnDestroy(): void
dispose(): void
createUrlTree(commands: any[], navigationExtras: NavigationExtras = {}): UrlTree
navigateByUrl(url: string | UrlTree, extras: NavigationExtras = { skipLocationChange: false }): 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> | 只读 An event stream for routing events in this NgModule. |
routerState: RouterState | 只读 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' | 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 | Declared in constructor. |
url: string | 只读 当前 URL The current URL. |
方法
设置位置变化监听器,并执行首次导航。 Sets up the location change listener and performs the initial navigation. |
设置位置变化监听器。 Sets up the location change listener. |
参数没有参数。 返回值
|
The current Navigation object if one exists |
重置供导航和生成链接使用的配置项。 Resets the configuration used for navigation and generating links. |
使用说明
|
参数没有参数。 返回值
|
销毁路由器 Disposes of the router. |
参数没有参数。 返回值
|
把一个命令数组应用于当前的 URL 树,并创建一个新的 URL 树。 Applies an array of commands to the current URL tree and creates a new URL tree. | ||||||
参数
返回值新的 URL Tree。
| ||||||
如果指定了激活路由,就以该路由为起点应用这些命令。 如果没有指定激活路由,就以根路由为起点应用这些命令。 When given an activated route, applies the given commands starting from the route. Otherwise, applies the given command starting from the root. | ||||||
使用说明
|
基于所提供的 URL 进行导航,必须使用绝对路径。 Navigate based on the provided URL, which must be absolute. | ||||||
参数
返回值一个 Promise,当导航成功时,它会解析成
| ||||||
使用说明
|
基于所提供的命令数组和起点路由进行导航。 如果没有指定起点路由,则从根路由开始进行绝对导航。 Navigate based on the provided array of commands and a starting point. If no starting route is provided, the navigation is absolute. | ||||||
参数
返回值
| ||||||
返回一个 Promise: Returns a promise that:
| ||||||
使用说明
The first parameter of 要想影响到浏览器的 In order to affect this browser's |
把 Serializes a |
把字符串解析为 Parses a string into a |
返回指定的 Returns whether the url is activated |