docs(API): 翻译完了 RouterModule

This commit is contained in:
Zhicheng Wang 2018-09-01 20:55:38 +08:00
parent ea796c6952
commit 10ddb2449f
2 changed files with 171 additions and 2 deletions

View File

@ -26,7 +26,7 @@
[x] |core/ViewChild | 2,870 | 0.89
[x] |core/Directive | 2,767 | 0.86
[x] |router/Routes | 2,331 | 0.72
[ ] |router/RouterModule | 2,227 | 0.69
[x] |router/RouterModule | 2,227 | 0.69
[x] |router/Route | 2,223 | 0.69
[ ] |common/http/HttpClientModule | 2,167 | 0.67
[ ] |core/ElementRef | 2,163 | 0.67

View File

@ -35,6 +35,7 @@ import {flatten} from './utils/collection';
*
* Contains a list of directives
*
*
*
*/
const ROUTER_DIRECTIVES =
@ -45,7 +46,7 @@ const ROUTER_DIRECTIVES =
*
* Is used in DI to configure the router.
*
*
* DI
*/
export const ROUTER_CONFIGURATION = new InjectionToken<ExtraOptions>('ROUTER_CONFIGURATION');
@ -86,16 +87,28 @@ export function routerNgProbeToken() {
* Since the router deals with a global shared resource--location, we cannot have
* more than one router service active.
*
* RouterModule
* - location `Router`
*
* That is why there are two ways to create the module: `RouterModule.forRoot` and
* `RouterModule.forChild`.
*
* `RouterModule.forRoot` `RouterModule.forChild`
*
* * `forRoot` creates a module that contains all the directives, the given routes, and the router
* service itself.
*
* `forRoot` `Router`
*
* * `forChild` creates a module that contains all the directives and the given routes, but does not
* include the router service.
*
* `forChild` `Router`
*
* When registered at the root, the module should be used as follows
*
*
*
* ```
* @NgModule({
* imports: [RouterModule.forRoot(ROUTES)]
@ -105,6 +118,8 @@ export function routerNgProbeToken() {
*
* For submodules and lazy loaded submodules the module should be used as follows:
*
*
*
* ```
* @NgModule({
* imports: [RouterModule.forChild(ROUTES)]
@ -116,18 +131,26 @@ export function routerNgProbeToken() {
*
* Adds router directives and providers.
*
*
*
* Managing state transitions is one of the hardest parts of building applications. This is
* especially true on the web, where you also need to ensure that the state is reflected in the URL.
* In addition, we often want to split applications into multiple bundles and load them on demand.
* Doing this transparently is not trivial.
*
* Web URL
*
*
* The Angular router solves these problems. Using the router, you can declaratively specify
* application states, manage state transitions while taking care of the URL, and load bundles on
* demand.
*
* Angular 使 URL
*
* [Read this developer guide](https://angular.io/docs/ts/latest/guide/router.html) to get an
* overview of how the router should be used.
*
* [](/guide/router) 使
*
*/
@NgModule({
@ -143,17 +166,43 @@ export class RouterModule {
* Creates a module with all the router providers and directives. It also optionally sets up an
* application listener to perform an initial navigation.
*
*
*
* Options (see `ExtraOptions`):
*
* `ExtraOptions`
*
* * `enableTracing` makes the router log all its internal events to the console.
*
* `enableTracing`
*
* * `useHash` enables the location strategy that uses the URL fragment instead of the history
* API.
*
* `useHash` `LocationStrategy` URL `#` `history` API
*
* * `initialNavigation` disables the initial navigation.
*
* `initialNavigation`
*
* * `errorHandler` provides a custom error handler.
*
* `errorHandler`
*
* * `preloadingStrategy` configures a preloading strategy (see `PreloadAllModules`).
*
* `preloadingStrategy` `PreloadAllModules`
*
* * `onSameUrlNavigation` configures how the router handles navigation to the current URL. See
* `ExtraOptions` for more details.
*
* `onSameUrlNavigation` URL `ExtraOptions`
*
* * `paramsInheritanceStrategy` defines how the router merges params, data and resolved data
* from parent to child routes.
*
* `paramsInheritanceStrategy`
*
*/
static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterModule> {
return {
@ -192,6 +241,8 @@ export class RouterModule {
/**
* Creates a module with all the router directives and a provider registering routes.
*
*
*/
static forChild(routes: Routes): ModuleWithProviders<RouterModule> {
return {ngModule: RouterModule, providers: [provideRoutes(routes)]};
@ -225,8 +276,12 @@ export function provideForRootGuard(router: Router): any {
*
* Registers routes.
*
*
*
* ### Example
*
* ###
*
* ```
* @NgModule({
* imports: [RouterModule.forChild(ROUTES)],
@ -249,24 +304,47 @@ export function provideRoutes(routes: Routes): any {
*
* Represents an option to configure when the initial navigation is performed.
*
*
*
* * 'enabled' - the initial navigation starts before the root component is created.
* The bootstrap is blocked until the initial navigation is complete.
*
* 'enabled' -
*
* * 'disabled' - the initial navigation is not performed. The location listener is set up before
* the root component gets created.
*
* 'disabled' -
*
* * 'legacy_enabled'- the initial navigation starts after the root component has been created.
* The bootstrap is not blocked until the initial navigation is complete. @deprecated
*
* 'legacy_enabled' - @deprecated
*
* * 'legacy_disabled'- the initial navigation is not performed. The location listener is set up
* after @deprecated
* the root component gets created.
*
* 'legacy_disabled' - @deprecated
*
* * `true` - same as 'legacy_enabled'. @deprecated since v4
*
* `true` - 'legacy_enabled'. @deprecated since v4
*
* * `false` - same as 'legacy_disabled'. @deprecated since v4
*
* `false` - 'legacy_disabled'. @deprecated since v4
*
* The 'enabled' option should be used for applications unless there is a reason to have
* more control over when the router starts its initial navigation due to some complex
* initialization logic. In this case, 'disabled' should be used.
*
* 使 'enabled'使 'disabled'
*
* The 'legacy_enabled' and 'legacy_disabled' should not be used for new applications.
*
* 使 'legacy_enabled' 'legacy_disabled'
*
* @experimental
*/
export type InitialNavigation =
@ -277,31 +355,42 @@ export type InitialNavigation =
*
* Represents options to configure the router.
*
*
*
*/
export interface ExtraOptions {
/**
* Makes the router log all its internal events to the console.
*
*
*/
enableTracing?: boolean;
/**
* Enables the location strategy that uses the URL fragment instead of the history API.
*
* `LocationStrategy` URL `#` `history` API
*/
useHash?: boolean;
/**
* Disables the initial navigation.
*
*
*/
initialNavigation?: InitialNavigation;
/**
* A custom error handler.
*
*
*/
errorHandler?: ErrorHandler;
/**
* Configures a preloading strategy. See `PreloadAllModules`.
*
* `PreloadAllModules`
*/
preloadingStrategy?: any;
@ -310,22 +399,41 @@ export interface ExtraOptions {
* By default, the router will ignore this navigation. However, this prevents features such
* as a "refresh" button. Use this option to configure the behavior when navigating to the
* current URL. Default is 'ignore'.
*
* URL
* "刷新"
* 使 URL 'ignore'
*/
onSameUrlNavigation?: 'reload'|'ignore';
/**
* Configures if the scroll position needs to be restored when navigating back.
*
*
*
* * 'disabled'--does nothing (default).
*
* 'disabled' -
*
* * 'top'--set the scroll position to 0,0..
*
* 'top' - 0,0
*
* * 'enabled'--set the scroll position to the stored position. This option will be the default in
* the future.
*
* 'enabled' -
*
* When enabled, the router store store scroll positions when navigating forward, and will
* restore the stored positions whe navigating back (popstate). When navigating forward,
* the scroll position will be set to [0, 0], or to the anchor if one is provided.
*
* popstate [0, 0]
*
* You can implement custom scroll restoration behavior as follows.
*
*
*
* ```typescript
* class AppModule {
* constructor(router: Router, viewportScroller: ViewportScroller, store: Store<AppState>) {
@ -346,6 +454,8 @@ export interface ExtraOptions {
*
* You can also implement component-specific scrolling like this:
*
*
*
* ```typescript
* class ListComponent {
* list: any[];
@ -367,20 +477,34 @@ export interface ExtraOptions {
/**
* Configures if the router should scroll to the element when the url has a fragment.
*
* url `#`
*
* * 'disabled'--does nothing (default).
*
* 'disabled' -
*
* * 'enabled'--scrolls to the element. This option will be the default in the future.
*
* 'enabled' -
*
* Anchor scrolling does not happen on 'popstate'. Instead, we restore the position
* that we stored or scroll to the top.
*
* 'popstate'
*/
anchorScrolling?: 'disabled'|'enabled';
/**
* Configures the scroll offset the router will use when scrolling to an element.
*
* 使
*
* When given a tuple with two numbers, the router will always use the numbers.
* When given a function, the router will invoke the function every time it restores scroll
* position.
*
* 使
*
*/
scrollOffset?: [number, number]|(() => [number, number]);
@ -388,9 +512,16 @@ export interface ExtraOptions {
* Defines how the router merges params, data and resolved data from parent to child
* routes. Available options are:
*
*
*
* - `'emptyOnly'`, the default, only inherits parent params for path-less or component-less
* routes.
*
* `'emptyOnly'`
*
* - `'always'`, enables unconditional inheritance of parent params.
*
* `'always'`
*/
paramsInheritanceStrategy?: 'emptyOnly'|'always';
@ -399,9 +530,20 @@ export interface ExtraOptions {
* invalid character sequences. The default implementation is to redirect to the root url dropping
* any path or param info. This function passes three parameters:
*
* URI encodeURI
*
* - `'URIError'` - Error thrown when parsing a bad URL
*
* `'URIError'` - URL
*
* - `'UrlSerializer'` - UrlSerializer thats configured with the router.
*
* `'UrlSerializer'` - UrlSerializer
*
* - `'url'` - The malformed URL that caused the URIError
*
* `'url'` - URIError URL
*
* */
malformedUriErrorHandler?:
(error: URIError, urlSerializer: UrlSerializer, url: string) => UrlTree;
@ -413,8 +555,17 @@ export interface ExtraOptions {
* URL early so if navigation fails, you can show an error message with the URL that failed.
* Available options are:
*
* URL
* URL URL
*
*
* - `'deferred'`, the default, updates the browser URL after navigation has finished.
*
* `'deferred'` URL
*
* - `'eager'`, updates browser URL at the beginning of navigation.
*
* `'eager'` URL
*/
urlUpdateStrategy?: 'deferred'|'eager';
@ -422,6 +573,8 @@ export interface ExtraOptions {
* Enables a bug fix that corrects relative link resolution in components with empty paths.
* Example:
*
* BUG
*
* ```
* const routes = [
* {
@ -437,14 +590,20 @@ export interface ExtraOptions {
*
* From the `ContainerComponent`, this will not work:
*
* `ContainerComponent`
*
* `<a [routerLink]="['./a']">Link to A</a>`
*
* However, this will work:
*
*
*
* `<a [routerLink]="['../a']">Link to A</a>`
*
* In other words, you're required to use `../` rather than `./`. The current default in v6
* is `legacy`, and this option will be removed in v7 to default to the corrected behavior.
*
* 使 `../` `./` v6 `legacy` v7
*/
relativeLinkResolution?: 'legacy'|'corrected';
}
@ -509,13 +668,21 @@ export function rootRoute(router: Router): ActivatedRoute {
/**
* To initialize the router properly we need to do in two steps:
*
*
*
* We need to start the navigation in a APP_INITIALIZER to block the bootstrap if
* a resolver or a guards executes asynchronously. Second, we need to actually run
* activation in a BOOTSTRAP_LISTENER. We utilize the afterPreactivation
* hook provided by the router to do that.
*
* APP_INITIALIZER 便
* BOOTSTRAP_LISTENER
* `afterPreactivation`
*
* The router navigation starts, reaches the point when preactivation is done, and then
* pauses. It waits for the hook to be resolved. We then resolve it only in a bootstrap listener.
*
* `preactivation`
*/
@Injectable()
export class RouterInitializer {
@ -607,6 +774,8 @@ export function getBootstrapListener(r: RouterInitializer) {
/**
* A token for the router initializer that will be called after the app is bootstrapped.
*
*
*
* @experimental
*/
export const ROUTER_INITIALIZER =