docs(API): 翻译完了 Routes

This commit is contained in:
Zhicheng Wang 2018-09-01 13:07:46 +08:00
parent a6d7c47763
commit cfd6494ade
2 changed files with 160 additions and 2 deletions

View File

@ -25,9 +25,9 @@
[x] |router/RouterLink | 2,929 | 0.91
[ ] |core/ViewChild | 2,870 | 0.89
[x] |core/Directive | 2,767 | 0.86
[ ] |router/Routes | 2,331 | 0.72
[x] |router/Routes | 2,331 | 0.72
[ ] |router/RouterModule | 2,227 | 0.69
[ ] |router/Route | 2,223 | 0.69
[x] |router/Route | 2,223 | 0.69
[ ] |common/http/HttpClientModule | 2,167 | 0.67
[ ] |core/ElementRef | 2,163 | 0.67
[ ] |core/OnInit | 2,136 | 0.66

View File

@ -17,34 +17,85 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
*
* Represents router configuration.
*
*
*
* `Routes` is an array of route configurations. Each one has the following properties:
*
* `Routes`
*
* - `path` is a string that uses the route matcher DSL.
*
* `path` DSL
*
* - `pathMatch` is a string that specifies the matching strategy.
*
* `pathMatch`
*
* - `matcher` defines a custom strategy for path matching and supersedes `path` and `pathMatch`.
*
* `matcher` `path` `pathMatch`
*
* - `component` is a component type.
*
* `component`
*
* - `redirectTo` is the url fragment which will replace the current matched segment.
*
* `redirectTo` URL URL
*
* - `outlet` is the name of the outlet the component should be placed into.
*
* `outlet`
*
* - `canActivate` is an array of DI tokens used to look up CanActivate handlers. See
* `CanActivate` for more info.
*
* `canActivate` DI `CanActivate` `CanActivate`
*
* - `canActivateChild` is an array of DI tokens used to look up CanActivateChild handlers. See
* `CanActivateChild` for more info.
*
* `canActivateChild` DI `CanActivateChild` `CanActivateChild`
*
* - `canDeactivate` is an array of DI tokens used to look up CanDeactivate handlers. See
* `CanDeactivate` for more info.
*
* `canDeactivate` DI `CanDeactivate` `CanDeactivate`
*
* - `canLoad` is an array of DI tokens used to look up CanLoad handlers. See
* `CanLoad` for more info.
*
* `canLoad` DI `CanLoad` `CanLoad`
*
* - `data` is additional data provided to the component via `ActivatedRoute`.
*
* `data` `ActivatedRoute`
*
* - `resolve` is a map of DI tokens used to look up data resolvers. See `Resolve` for more
* info.
*
* `resolve` DI `Resolve`
*
* - `runGuardsAndResolvers` defines when guards and resolvers will be run. By default they run only
* when the matrix parameters of the route change. When set to `paramsOrQueryParamsChange` they
* will also run when query params change. And when set to `always`, they will run every time.
*
* `runGuardsAndResolvers` `#`
* `paramsOrQueryParamsChange` `?` `always`
*
* - `children` is an array of child route definitions.
*
* `children`
*
* - `loadChildren` is a reference to lazy loaded child routes. See `LoadChildren` for more
* info.
*
* `loadChildren` `LoadChildren`
*
* ### Simple Configuration
*
* ###
*
* ```
* [{
* path: 'team/:id',
@ -59,8 +110,12 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* When navigating to `/team/11/user/bob`, the router will create the team component with the user
* component in it.
*
* `/team/11/user/bob` Team User
*
* ### Multiple Outlets
*
* ###
*
* ```
* [{
* path: 'team/:id',
@ -75,8 +130,12 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* When navigating to `/team/11(aux:chat/jim)`, the router will create the team component next to
* the chat component. The chat component will be placed into the aux outlet.
*
* `/team/11(aux:chat/jim)` Chat Team Chat `aux`
*
* ### Wild Cards
*
* ###
*
* ```
* [{
* path: '**',
@ -86,8 +145,12 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
*
* Regardless of where you navigate to, the router will instantiate the sink component.
*
* Sink
*
* ### Redirects
*
* ###
*
* ```
* [{
* path: 'team/:id',
@ -106,14 +169,23 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* '/team/11/user/jim', and then will instantiate the team component with the user component
* in it.
*
* '/team/11/legacy/user/jim' URL '/team/11/user/jim' Team User
*
* If the `redirectTo` value starts with a '/', then it is an absolute redirect. E.g., if in the
* example above we change the `redirectTo` to `/user/:name`, the result url will be '/user/jim'.
*
* `redirectTo` `/` `redirectTo` `/user/:name`
* url `'/user/jim'`
*
* ### Empty Path
*
* ###
*
* Empty-path route configurations can be used to instantiate components that do not 'consume'
* any url segments. Let's look at the following configuration:
*
* "消费" url
*
* ```
* [{
* path: 'team/:id',
@ -130,8 +202,12 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
*
* When navigating to `/team/11`, the router will instantiate the AllUsers component.
*
* `/team/11` AllUsers
*
* Empty-path routes can have children.
*
*
*
* ```
* [{
* path: 'team/:id',
@ -150,19 +226,31 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* When navigating to `/team/11/user/jim`, the router will instantiate the wrapper component with
* the user component in it.
*
* `/team/11/user/jim` `WrapperCmp` `User`
*
* An empty path route inherits its parent's params and data. This is because it cannot have its
* own params, and, as a result, it often uses its parent's params and data as its own.
*
* 使
*
* ### Matching Strategy
*
* ###
*
* By default the router will look at what is left in the url, and check if it starts with
* the specified path (e.g., `/team/11/user` starts with `team/:id`).
*
* URL `/team/11/user` `team/:id`
*
* We can change the matching strategy to make sure that the path covers the whole unconsumed url,
* which is akin to `unconsumedUrl === path` or `$` regular expressions.
*
* url `unconsumedUrl === path` `$`
*
* This is particularly important when redirecting empty-path routes.
*
*
*
* ```
* [{
* path: '',
@ -177,9 +265,13 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* Since an empty path is a prefix of any url, even when navigating to '/main', the router will
* still apply the redirect.
*
* url 使 '/main'
*
* If `pathMatch: full` is provided, the router will apply the redirect if and only if navigating to
* '/'.
*
* `pathMatch: full` `'/'`
*
* ```
* [{
* path: '',
@ -193,14 +285,22 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
*
* ### Componentless Routes
*
* ###
*
* It is useful at times to have the ability to share parameters between sibling components.
*
*
*
* Say we have two components--ChildCmp and AuxCmp--that we want to put next to each other and both
* of them require some id parameter.
*
* `ChildCmp` `AuxCmp` `id`
*
* One way to do that would be to have a bogus parent component, so both the siblings can get the id
* parameter from it. This is not ideal. Instead, you can use a componentless route.
*
* id
*
* ```
* [{
* path: 'parent/:id',
@ -215,12 +315,19 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* child components next to each other. In this example, the application component
* has to have the primary and aux outlets defined.
*
* `parent/10/(a//aux:b)` `aux`
*
* The router will also merge the `params`, `data`, and `resolve` of the componentless parent into
* the `params`, `data`, and `resolve` of the children. This is done because there is no component
* that can inject the activated route of the componentless parent.
*
* `params``data` `resolve` `params``data` `resolve`
*
*
* This is especially useful when child components are defined as follows:
*
*
*
* ```
* [{
* path: 'parent/:id',
@ -234,12 +341,19 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* With this configuration in place, navigating to '/parent/10' will create the main child and aux
* components.
*
* 使 '/parent/10'
*
* ### Lazy Loading
*
* ###
*
* Lazy loading speeds up our application load time by splitting it into multiple bundles, and
* loading them on demand. The router is designed to make lazy loading simple and easy. Instead of
* providing the children property, you can provide the `loadChildren` property, as follows:
*
*
* `loadChildren` `children`
*
* ```
* [{
* path: 'team/:id',
@ -252,15 +366,25 @@ import {UrlSegment, UrlSegmentGroup} from './url_tree';
* Then it will extract the set of routes defined in that NgModule, and will transparently add
* those routes to the main configuration.
*
* 使 `NgModuleFactoryLoader` `team` NgModule
* NgModule
*
*/
export type Routes = Route[];
/**
* @description Represents the results of the URL matching.
*
* URL
*
* * `consumed` is an array of the consumed URL segments.
*
* `consumed` URL
*
* * `posParams` is a map of positional parameters.
*
* `posParams`
*
* @experimental
*/
export type UrlMatchResult = {
@ -272,11 +396,17 @@ export type UrlMatchResult = {
*
* A function matching URLs
*
* URL
*
* A custom URL matcher can be provided when a combination of `path` and `pathMatch` isn't
* expressive enough.
*
* `path` `pathMatch` URL
*
* For instance, the following matcher matches html files.
*
* html
*
* ```
* export function htmlFiles(url: UrlSegment[]) {
* return url.length === 1 && url[0].path.endsWith('.html') ? ({consumed: url}) : null;
@ -295,8 +425,12 @@ export type UrlMatcher = (segments: UrlSegment[], group: UrlSegmentGroup, route:
*
* Represents the static data associated with a particular route.
*
*
*
* See `Routes` for more details.
*
* `Routes`
*
*/
export type Data = {
[name: string]: any
@ -307,8 +441,12 @@ export type Data = {
*
* Represents the resolved data associated with a particular route.
*
*
*
* See `Routes` for more details.
*
* `Routes`
*
*/
export type ResolveData = {
[name: string]: any
@ -319,8 +457,12 @@ export type ResolveData = {
*
* The type of `loadChildren`.
*
* `loadChildren`
*
* See `Routes` for more details.
*
* `Routes`
*
*/
export type LoadChildrenCallback = () =>
Type<any>| NgModuleFactory<any>| Promise<Type<any>>| Observable<Type<any>>;
@ -330,8 +472,11 @@ export type LoadChildrenCallback = () =>
*
* The type of `loadChildren`.
*
* `loadChildren`
*
* See `Routes` for more details.
*
* `Routes`
*/
export type LoadChildren = string | LoadChildrenCallback;
@ -340,8 +485,11 @@ export type LoadChildren = string | LoadChildrenCallback;
*
* The type of `queryParamsHandling`.
*
* `queryParamsHandling`
*
* See `RouterLink` for more details.
*
* `RouterLink`
*/
export type QueryParamsHandling = 'merge' | 'preserve' | '';
@ -350,7 +498,12 @@ export type QueryParamsHandling = 'merge' | 'preserve' | '';
*
* The type of `runGuardsAndResolvers`.
*
* `runGuardsAndResolvers`
*
* See `Routes` for more details.
*
* `Routes`
*
* @experimental
*/
export type RunGuardsAndResolvers = 'paramsChange' | 'paramsOrQueryParamsChange' | 'always';
@ -358,6 +511,8 @@ export type RunGuardsAndResolvers = 'paramsChange' | 'paramsOrQueryParamsChange'
/**
* See `Routes` for more details.
*
* `Routes`
*
*/
export interface Route {
path?: string;
@ -480,6 +635,9 @@ function getFullPath(parentPath: string, currentRoute: Route): string {
/**
* Makes a copy of the config and adds any default required properties.
*
* required
*
*/
export function standardizeConfig(r: Route): Route {
const children = r.children && r.children.map(standardizeConfig);