Skip to content

Commit dd5d940

Browse files
committed
docs: 新增 getRoute 方法的文档,包含版本信息、功能描述及示例代码。
1 parent 3e01dcf commit dd5d940

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/en/api/api.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ const router = getRouter();
127127
router.push('/hello');
128128
```
129129
130+
### getRoute
131+
132+
- **Version**:<VersionTag version="0.17.4" />
133+
134+
Return the current routing object information of the router. It is equivalent to using $route in the template syntax and is only applicable to vue-router 3.x.
135+
136+
Type definition:
137+
```ts
138+
getRoute(): Route
139+
```
140+
141+
```ts
142+
import { getRoute } from 'winjs';
143+
144+
export const getCurrentRoute = () => {
145+
const route = getRoute();
146+
console.log('current route:', route?.path);
147+
return route;
148+
};
149+
```
150+
130151
### onBeforeRouteUpdate
131152
132153
Adds a navigation guard that is triggered whenever the current location is updated. Similar to `beforeRouteUpdate`, but can be used in any component. The guard is removed when the component is unmounted.

src/zh/api/api.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ const router = getRouter();
127127
router.push('/hello');
128128
```
129129
130+
### getRoute
131+
132+
- **版本**:<VersionTag version="0.17.4" />
133+
134+
返回路由器 router 的当前路由对象信息,相当于在模板语法中使用 $route,只适用于 vue-router 3.x。
135+
136+
类型定义如下:
137+
```ts
138+
getRoute(): Route
139+
```
140+
141+
```ts
142+
import { getRoute } from 'winjs';
143+
144+
export const getCurrentRoute = () => {
145+
const route = getRoute();
146+
console.log('当前路由:', route?.path);
147+
return route;
148+
};
149+
```
150+
130151
### onBeforeRouteUpdate
131152
132153
添加一个导航守卫,不论当前位置何时被更新都会触发。类似于 `beforeRouteUpdate`,但可以在任何组件中使用。当组件被卸载时,该守卫会被移除。

0 commit comments

Comments
 (0)