Skip to content

Commit

Permalink
dosc(zh): translate api/router (vuejs#1822)
Browse files Browse the repository at this point in the history
* dosc(zh): translate first half of api router

* dosc(zh): translate all in the api router

* Apply suggestions from code review

Co-authored-by: wxsm <[email protected]>

---------

Co-authored-by: wxsm <[email protected]>
  • Loading branch information
Jinjiang and wxsms authored May 9, 2023
1 parent c49541a commit 4ca3c8c
Showing 1 changed file with 40 additions and 72 deletions.
112 changes: 40 additions & 72 deletions packages/docs/zh/api/interfaces/Router.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,76 @@ editLink: false

# Interface: Router

Router instance.
路由器实例。

## Properties %{#Properties}%

### currentRoute %{#Properties-currentRoute}%

`Readonly` **currentRoute**: `Ref`<[`RouteLocationNormalizedLoaded`](RouteLocationNormalizedLoaded.md)\>

Current [RouteLocationNormalized](RouteLocationNormalized.md)
当前的 [RouteLocationNormalized](RouteLocationNormalized.md)

___

### listening %{#Properties-listening}%

**listening**: `boolean`

Allows turning off the listening of history events. This is a low level api for micro-frontends.
允许关闭历史事件的监听器。这是一个为微前端提供的底层 API。

___

### options %{#Properties-options}%

`Readonly` **options**: [`RouterOptions`](RouterOptions.md)

Original options object passed to create the Router
创建路由器时的原始选项对象。

## Methods %{#Methods}%

### addRoute %{#Methods-addRoute}%

**addRoute**(`parentName`, `route`): () => `void`

Add a new [route record](../index.md#routerecordraw) as the child of an existing route.
添加一个新的[路由记录](../index.md#routerecordraw),将其作为一个已有路由的子路由。

#### Parameters %{#Methods-addRoute-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `parentName` | [`RouteRecordName`](../index.md#routerecordname) | Parent Route Record where `route` should be appended at |
| `route` | [`RouteRecordRaw`](../index.md#routerecordraw) | Route Record to add |
| `parentName` | [`RouteRecordName`](../index.md#routerecordname) | `route` 应该被加入到的父级路由记录 |
| `route` | [`RouteRecordRaw`](../index.md#routerecordraw) | 要加入的路由记录 |

#### Returns %{#Methods-addRoute-Returns}%

`fn`

▸ (): `void`

Add a new [route record](../index.md#routerecordraw) as the child of an existing route.
添加一个新的[路由记录](../index.md#routerecordraw),将其作为一个已有路由的子路由。

##### Returns %{#Methods-addRoute-Returns-Returns}%

`void`

**addRoute**(`route`): () => `void`

Add a new [route record](../index.md#routerecordraw) to the router.
添加一个新的[路由记录](../index.md#routerecordraw)到该路由器中。

#### Parameters %{#Methods-addRoute-Parameters_1}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `route` | [`RouteRecordRaw`](../index.md#routerecordraw) | Route Record to add |
| `route` | [`RouteRecordRaw`](../index.md#routerecordraw) | 要加入的路由记录 |

#### Returns %{#Methods-addRoute-Returns_1}%

`fn`

▸ (): `void`

Add a new [route record](../index.md#routerecordraw) to the router.
添加一个新的[路由记录](../index.md#routerecordraw)到该路由器中。

##### Returns %{#Methods-addRoute-Returns-Returns_1}%

Expand All @@ -87,8 +87,7 @@ ___

**afterEach**(`guard`): () => `void`

Add a navigation hook that is executed after every navigation. Returns a
function that removes the registered hook.
添加一个导航钩子,它会在每次导航之后被执行。返回一个用来移除该钩子的函数。

**`Example`**

Expand All @@ -104,16 +103,15 @@ router.afterEach((to, from, failure) => {

| Name | Type | Description |
| :------ | :------ | :------ |
| `guard` | [`NavigationHookAfter`](NavigationHookAfter.md) | navigation hook to add |
| `guard` | [`NavigationHookAfter`](NavigationHookAfter.md) | 要加入的导航钩子 |

#### Returns %{#Methods-afterEach-Returns}%

`fn`

▸ (): `void`

Add a navigation hook that is executed after every navigation. Returns a
function that removes the registered hook.
添加一个导航钩子,它会在每次导航之后被执行。返回一个用来移除该钩子的函数。

**`Example`**

Expand All @@ -135,8 +133,7 @@ ___

**back**(): `void`

Go back in history if possible by calling `history.back()`. Equivalent to
`router.go(-1)`.
通过调用 `history.back()` 在可能的情况下在历史中后退。相当于 `router.go(-1)`

#### Returns %{#Methods-back-Returns}%

Expand All @@ -148,23 +145,21 @@ ___

**beforeEach**(`guard`): () => `void`

Add a navigation guard that executes before any navigation. Returns a
function that removes the registered guard.
添加一个导航钩子,它会在每次导航之前被执行。返回一个用来移除该钩子的函数。

#### Parameters %{#Methods-beforeEach-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `guard` | [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\> | navigation guard to add |
| `guard` | [`NavigationGuardWithThis`](NavigationGuardWithThis.md)<`undefined`\> | 要加入的导航钩子 |

#### Returns %{#Methods-beforeEach-Returns}%

`fn`

▸ (): `void`

Add a navigation guard that executes before any navigation. Returns a
function that removes the registered guard.
添加一个导航钩子,它会在每次导航之前被执行。返回一个用来移除该钩子的函数。

##### Returns %{#Methods-beforeEach-Returns-Returns}%

Expand All @@ -176,10 +171,7 @@ ___

**beforeResolve**(`guard`): () => `void`

Add a navigation guard that executes before navigation is about to be
resolved. At this state all component have been fetched and other
navigation guards have been successful. Returns a function that removes the
registered guard.
添加一个导航守卫,它会在导航将要被解析之前被执行。此时所有组件都已经获取完毕,且其它导航守卫也都已经完成调用。返回一个用来移除该守卫的函数。

**`Example`**

Expand All @@ -201,10 +193,7 @@ router.beforeResolve(to => {

▸ (): `void`

Add a navigation guard that executes before navigation is about to be
resolved. At this state all component have been fetched and other
navigation guards have been successful. Returns a function that removes the
registered guard.
添加一个导航守卫,它会在导航将要被解析之前被执行。此时所有组件都已经获取完毕,且其它导航守卫也都已经完成调用。返回一个用来移除该守卫的函数。

**`Example`**

Expand All @@ -224,8 +213,7 @@ ___

**forward**(): `void`

Go forward in history if possible by calling `history.forward()`.
Equivalent to `router.go(1)`.
通过调用 `history.forward()` 在可能的情况下在历史中前进。相当于 `router.go(1)`

#### Returns %{#Methods-forward-Returns}%

Expand All @@ -237,7 +225,7 @@ ___

**getRoutes**(): [`RouteRecordNormalized`](RouteRecordNormalized.md)[]

Get a full list of all the [route records](../index.md#routerecord).
获得所有[路由记录](../index.md#routerecord)的完整列表。

#### Returns %{#Methods-getRoutes-Returns}%

Expand All @@ -249,14 +237,13 @@ ___

**go**(`delta`): `void`

Allows you to move forward or backward through the history. Calls
`history.go()`.
允许你在历史中前进或后退。相当于 `router.go()`

#### Parameters %{#Methods-go-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `delta` | `number` | The position in the history to which you want to move, relative to the current page |
| `delta` | `number` | 相对于当前页面你想要移动到的历史中的位置 |

#### Returns %{#Methods-go-Returns}%

Expand All @@ -268,13 +255,13 @@ ___

**hasRoute**(`name`): `boolean`

Checks if a route with a given name exists
检查一个给定名称的路由是否存在。

#### Parameters %{#Methods-hasRoute-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | [`RouteRecordName`](../index.md#routerecordname) | Name of the route to check |
| `name` | [`RouteRecordName`](../index.md#routerecordname) | 要检查的路由名称 |

#### Returns %{#Methods-hasRoute-Returns}%

Expand All @@ -286,15 +273,9 @@ ___

**isReady**(): `Promise`<`void`\>

Returns a Promise that resolves when the router has completed the initial
navigation, which means it has resolved all async enter hooks and async
components that are associated with the initial route. If the initial
navigation already happened, the promise resolves immediately.
返回一个 Promise,它会在路由器完成初始导航之后被解析,也就是说这时所有和初始路由有关联的异步入口钩子和异步组件都已经被解析。如果初始导航已经发生,则该 Promise 会被立刻解析。

This is useful in server-side rendering to ensure consistent output on both
the server and the client. Note that on server side, you need to manually
push the initial location while on client side, the router automatically
picks it up from the URL.
这在服务端渲染中确认服务端和客户端输出一致的时候非常有用。注意在服务端你需要手动加入初始地址,而在客户端,路由器会从 URL 中自动获取。

#### Returns %{#Methods-isReady-Returns}%

Expand All @@ -306,29 +287,21 @@ ___

**onError**(`handler`): () => `void`

Adds an error handler that is called every time a non caught error happens
during navigation. This includes errors thrown synchronously and
asynchronously, errors returned or passed to `next` in any navigation
guard, and errors occurred when trying to resolve an async component that
is required to render a route.
添加一个错误处理器,它会在每次导航遇到未被捕获的错误出现时被调用。其中包括同步和异步被抛出的错误、在任何导航守卫中返回或传入 `next` 的错误、尝试解析一个需要渲染路由的异步组件时发生的错误。

#### Parameters %{#Methods-onError-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `handler` | `_ErrorHandler` | error handler to register |
| `handler` | `_ErrorHandler` | 要注册的错误处理器 |

#### Returns %{#Methods-onError-Returns}%

`fn`

▸ (): `void`

Adds an error handler that is called every time a non caught error happens
during navigation. This includes errors thrown synchronously and
asynchronously, errors returned or passed to `next` in any navigation
guard, and errors occurred when trying to resolve an async component that
is required to render a route.
添加一个错误处理器,它会在每次导航遇到未被捕获的错误出现时被调用。其中包括同步和异步被抛出的错误、在任何导航守卫中返回或传入 `next` 的错误、尝试解析一个需要渲染路由的异步组件时发生的错误。

##### Returns %{#Methods-onError-Returns-Returns}%

Expand All @@ -340,14 +313,13 @@ ___

**push**(`to`): `Promise`<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\>

Programmatically navigate to a new URL by pushing an entry in the history
stack.
程序式地通过将一条记录加入到历史栈中来导航到一个新的 URL。

#### Parameters %{#Methods-push-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `to` | [`RouteLocationRaw`](../index.md#routelocationraw) | Route location to navigate to |
| `to` | [`RouteLocationRaw`](../index.md#routelocationraw) | 要导航到的路由 |

#### Returns %{#Methods-push-Returns}%

Expand All @@ -359,13 +331,13 @@ ___

**removeRoute**(`name`): `void`

Remove an existing route by its name.
根据其名称移除一个现有的路由。

#### Parameters %{#Methods-removeRoute-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | [`RouteRecordName`](../index.md#routerecordname) | Name of the route to remove |
| `name` | [`RouteRecordName`](../index.md#routerecordname) | 要移除的路由名称 |

#### Returns %{#Methods-removeRoute-Returns}%

Expand All @@ -377,14 +349,13 @@ ___

**replace**(`to`): `Promise`<`undefined` \| `void` \| [`NavigationFailure`](NavigationFailure.md)\>

Programmatically navigate to a new URL by replacing the current entry in
the history stack.
程序式地通过替换历史栈中的当前记录来导航到一个新的 URL。

#### Parameters %{#Methods-replace-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `to` | [`RouteLocationRaw`](../index.md#routelocationraw) | Route location to navigate to |
| `to` | [`RouteLocationRaw`](../index.md#routelocationraw) | 要导航到的路由 |

#### Returns %{#Methods-replace-Returns}%

Expand All @@ -396,17 +367,14 @@ ___

**resolve**(`to`, `currentLocation?`): [`RouteLocation`](RouteLocation.md) & { `href`: `string` }

Returns the [normalized version](RouteLocation.md) of a
[route location](../index.md#routelocationraw). Also includes an `href` property
that includes any existing `base`. By default, the `currentLocation` used is
`router.currentRoute` and should only be overridden in advanced use cases.
返回一个[路由地址](../index.md#routelocationraw)[规范化版本](RouteLocation.md)。同时包含一个包含任何现有 `base``href` 属性。默认情况下,用于 `router.currentRoute``currentLocation` 应该在特别高阶的用例下才会被覆写。

#### Parameters %{#Methods-resolve-Parameters}%

| Name | Type | Description |
| :------ | :------ | :------ |
| `to` | [`RouteLocationRaw`](../index.md#routelocationraw) | Raw route location to resolve |
| `currentLocation?` | [`RouteLocationNormalizedLoaded`](RouteLocationNormalizedLoaded.md) | Optional current location to resolve against |
| `to` | [`RouteLocationRaw`](../index.md#routelocationraw) | 要解析的原始路由地址 |
| `currentLocation?` | [`RouteLocationNormalizedLoaded`](RouteLocationNormalizedLoaded.md) | 可选的被解析的当前地址 |

#### Returns %{#Methods-resolve-Returns}%

Expand Down

0 comments on commit 4ca3c8c

Please sign in to comment.