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: 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
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, matchOptions: boolean | IsActiveMatchOptions): boolean
}
参见
Provided in
构造函数
创建路由器服务。 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. |
参数没有参数。 返回值
|
Returns the current |
重置供导航和生成链接使用的配置项。 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 |
3 个重载形式...显示所有 隐藏所有 expand_moreOverload #1Returns whether the url is activated.
Deprecated Use
参数
返回值
Overload #2Returns whether the url is activated.
参数
返回值
Overload #3
参数
返回值
|