@angular/router
Implements the Angular Router service , which enables navigation from one view to the next as users perform application tasks.
Defines the Route
object that maps a URL path to a component, and the RouterOutlet
directive that you use to place a routed view in a template, as well as a complete API for configuring, querying, and controlling the router state.
Import RouterModule
to use the Router service in your app. For more usage information, see the Routing and Navigation guide.
入口点
Entry points
主要
Primary
@angular/router | Implements the Angular Router service , which enables navigation from one view to the next as users perform application tasks. |
次要
Secondary
@angular/router/testing | Supplies a testing module for the Angular |
@angular/router/upgrade | Provides support for upgrading routing applications from Angular JS to Angular. |
主要入口点的导出
Primary entry point exports
NgModules
RouterModule | 添加指令和提供者,以便在应用程序中定义的视图之间进行应用内导航。使用 Angular Adds directives and providers for in-app navigation among views defined in an application. Use the Angular |
类
Classes
ActivatedRoute | 允许访问与某出口中加载的组件关联路由信息。用于遍历 Provides access to information about a route associated with a component that is loaded in an outlet. Use to traverse the |
ActivatedRouteSnapshot | 包含与当前组件相关的路由的当前瞬间信息。 Contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to traverse the router state tree. |
ActivationEnd | 在路由的“解析”阶段的激活部分结束时触发的事件。 An event triggered at the end of the activation part of the Resolve phase of routing. |
ActivationStart | 在路由的“解析”阶段的激活部分开始时触发的事件。 An event triggered at the start of the activation part of the Resolve phase of routing. |
BaseRouteReuseStrategy | 此基本路由复用策略仅在匹配的路由器配置完全相同时复用路由。这样可以防止仅在片段或查询参数发生更改时销毁和重新创建组件(也就是复用现有组件)。 This base route reuse strategy only reuses routes when the matched router configs are identical. This prevents components from being destroyed and recreated when just the fragment or query parameters change (that is, the existing component is reused). |
ChildActivationEnd | 在路由的“解析”阶段的子路由激活部分结束时触发的事件。 An event triggered at the end of the child-activation part of the Resolve phase of routing. |
ChildActivationStart | 在路由的“解析”阶段的子路由激活部分开始时触发的事件。 An event triggered at the start of the child-activation part of the Resolve phase of routing. |
ChildrenOutletContexts | 存储关于子级(=嵌套) Store contextual information about the children (= nested) |
DefaultUrlSerializer |
A default implementation of the |
GuardsCheckEnd | 表示路由的守卫( An event triggered at the end of the Guard phase of routing. |
GuardsCheckStart | 表示路由的守卫( An event triggered at the start of the Guard phase of routing. |
NavigationCancel | 直接或间接取消导航时触发的事件。当路由守卫返回了 An event triggered when a navigation is canceled, directly or indirectly. This can happen when a route guard returns |
NavigationEnd | 表示当导航成功结束时触发的事件。 An event triggered when a navigation ends successfully. |
NavigationError | 表示当导航出错时触发的事件。 An event triggered when a navigation fails due to an unexpected error. |
NavigationStart | 代表导航开始时触发的事件。 An event triggered when a navigation starts. |
NoPreloading | 提供不预加载任何模块的预加载策略。 Provides a preloading strategy that does not preload any modules. |
OutletContext | 存储关于 Store contextual information about a |
PreloadAllModules | 提供一种预加载策略,以尽快预加载所有模块。 Provides a preloading strategy that preloads all modules as quickly as possible. |
PreloadingStrategy | 提供预加载策略。 Provides a preloading strategy. |
ResolveEnd | 在路由的“解析”阶段结束时触发的事件。 An event triggered at the end of the Resolve phase of routing. |
ResolveStart | 在路由的“解析”阶段开始时触发的事件。 An event triggered at the start of the Resolve phase of routing. |
RouteConfigLoadEnd | 表示当某个路由被惰性加载时触发的事件。 An event triggered when a route has been lazy loaded. |
RouteConfigLoadStart | 表示在惰性加载某个路由配置前触发的事件。 An event triggered before lazy loading a route configuration. |
RouteReuseStrategy | 提供一种自定义复用已激活路由的方式。 Provides a way to customize when activated routes get reused. |
Router | 一个提供导航和操纵 URL 能力的 NgModule。 A service that provides navigation among views and URL manipulation capabilities. |
RouterEvent | 路由器相关事件的(而不是关于特定路由的)基类。对于任何指定的导航, Base for events the router goes through, as opposed to events tied to a specific route. Fired one time for any given navigation. |
RouterPreloader | 预加载器会乐观加载所有路由器配置,以使导航到应用程序的惰性加载部分的速度更快。 The preloader optimistically loads all router configurations to make navigations into lazily-loaded sections of the application faster. |
RouterState | 将路由器的状态表示为已激活路由的树。 Represents the state of the router as a tree of activated routes. |
RouterStateSnapshot | 表示路由器在当前瞬间的状态。 Represents the state of the router at a moment in time. |
RoutesRecognized | 表示当路由被识别出来时触发的事件。 An event triggered when routes are recognized. |
Scroll | 表示一个滚动事件。 An event triggered by scrolling. |
UrlHandlingStrategy | 提供一种将 AngularJS 应用程序迁移到 Angular 的方法。 Provides a way to migrate AngularJS applications to Angular. |
UrlSegment | 表示一个 URL 段。 Represents a single URL segment. |
UrlSegmentGroup | 表示已解析的 URL 段组。 Represents the parsed URL segment group. |
UrlSerializer | 将 URL 字符串序列化和反序列化为 URL 树。 Serializes and deserializes a URL string into a URL tree. |
UrlTree | 代表已解析的 URL。 Represents the parsed URL. |
函数
Functions
convertToParamMap | |
provideRoutes | 为一组路由注册一个 DI 提供者。 Registers a DI provider for a set of routes. |
结构
Structures
CanActivate | 类可以实现的接口,用于确定是否可以激活路由。如果所有守卫都返回了 Interface that a class can implement to be a guard deciding if a route can be activated. If all guards return |
CanActivateChild | 类可以实现的接口,用于确定是否可以激活子路由。如果所有守卫都返回了 Interface that a class can implement to be a guard deciding if a child route can be activated. If all guards return |
CanDeactivate | 类可以实现的接口,用于确定是否可以离开某个路由。如果所有守卫都返回了 Interface that a class can implement to be a guard deciding if a route can be deactivated. If all guards return |
CanLoad | 类可以实现的接口,用于确定是否可以加载子路由。如果所有守卫都返回了 Interface that a class can implement to be a guard deciding if children can be loaded. If all guards return |
ExtraOptions | 在 A set of configuration options for a router module, provided in the |
IsActiveMatchOptions | A set of options which specify how to determine if a |
NavigationBehaviorOptions | 修改 Options that modify the |
NavigationExtras | 修改 Options that modify the |
ParamMap | 提供访问特定于路由的必需和可选参数的映射表。该映射表支持使用 A map that provides access to the required and optional parameters specific to a route. The map supports retrieving a single value with |
Resolve | 可以实现为数据提供者的类的接口。数据提供者类可与路由器一起使用,以在导航期间解析数据。接口定义了开始导航时调用 Interface that classes can implement to be a data provider. A data provider class can be used with the router to resolve data during navigation. The interface defines a |
Route | 定义单个路由的配置对象。在 A configuration object that defines a single route. A set of routes are collected in a |
RouterOutletContract | An interface that defines the contract for developing a component outlet for the |
UrlCreationOptions | 本选项用来修改 Options that modify the |
指令
Directives
RouterLink | 当应用于模板中的元素时,使该元素成为开始导航到某个路由的链接。导航会在页面上的 When applied to an element in a template, makes that element a link that initiates navigation to a route. Navigation opens one or more routed components in one or more |
RouterLinkActive | 跟踪元素上的链接路由当前是否处于活动状态,并允许你指定一个或多个 CSS 类,以便在链接路由处于活动状态时添加到该元素。 Tracks whether the linked route of an element is currently active, and allows you to specify one or more CSS classes to add to the element when the linked route is active. |
RouterLinkWithHref | 允许你在应用中链接到特定的路由。 Lets you link to specific routes in your app. |
RouterOutlet | 一个占位符,Angular 会根据当前的路由器状态动态填充它。 Acts as a placeholder that Angular dynamically fills based on the current router state. |
类型
Types
Data | 表示与特定路由关联的静态数据。 Represents static data associated with a particular route. |
DeprecatedLoadChildren | 已弃用: The 不推荐使用 格式为 A string of the form |
DetachedRouteHandle | 表示已分离的路由树。 Represents the detached route tree. |
Event | 路由器事件能让你跟踪路由器的生命周期。 Router events that allow you to track the lifecycle of the router. |
InitialNavigation |
Allowed values in an |
LoadChildren | 本函数返回一组要加载的路由。 A function that returns a set of routes to load. |
LoadChildrenCallback | 调用此函数以解析惰性加载的路由集合。必须是以下形式的箭头函数: A function that is called to resolve a collection of lazy-loaded routes. Must be an arrow function of the following form: |
Navigation | 有关导航操作的信息。使用 Router.getCurrentNavigation() 方法检索最新的导航对象。 Information about a navigation operation. Retrieve the most recent navigation object with the Router.getCurrentNavigation() method . |
PRIMARY_OUTLET | 主路由出口的名字。 The primary routing outlet. |
Params | 矩阵和查询 URL 参数的集合。 A collection of matrix and query URL parameters. |
QueryParamsHandling | 如何处理路由器链接中的查询参数。为下列值之一: How to handle query parameters in a router link. One of: |
ROUTER_CONFIGURATION | DI 用它来配置路由器。 A DI token for the router service. |
ROUTER_INITIALIZER | 一个代表路由器初始化器的令牌,应用引导完毕后就会调用它。 A DI token for the router initializer that is called after the app is bootstrapped. |
ROUTES | 路由器配置的 DI 令牌。 The DI token for a router configuration. |
ResolveData | 表示与特定路由关联的已解析数据。 Represents the resolved data associated with a particular route. |
Routes | 表示路由器服务的路由配置。是一个 Represents a route configuration for the Router service. An array of |
RunGuardsAndResolvers | 何时在路由上运行守卫(guard)和解析器(resolver)的策略。 A policy for when to run guards and resolvers on a route. |
UrlMatchResult | 表示使用自定义匹配函数时的 URL 匹配结果。 Represents the result of matching URLs with a custom matching function. |
UrlMatcher | 一个用于匹配路由和 URL 的函数。 当 A function for matching a route against URLs. Implement a custom URL matcher for |