vitarx-router 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/router/helper.d.ts +92 -0
- package/dist/router/index.d.ts +6 -0
- package/dist/router/memory-router.d.ts +45 -0
- package/dist/router/router.d.ts +414 -0
- package/dist/router/type.d.ts +477 -0
- package/dist/router/update.d.ts +8 -0
- package/dist/router/utils.d.ts +152 -0
- package/dist/router/validate/index.d.ts +2 -0
- package/dist/router/validate/inject-props.d.ts +8 -0
- package/dist/router/validate/validate-widget.d.ts +8 -0
- package/dist/router/web-history-router.d.ts +65 -0
- package/dist/vitarx-router.js +1223 -0
- package/dist/widget/RouterView.d.ts +84 -0
- package/dist/widget/index.d.ts +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Element, VNode, Widget } from 'vitarx';
|
|
2
|
+
import { RouteNormalized } from '../router/index.js';
|
|
3
|
+
export interface RouteOptions {
|
|
4
|
+
/**
|
|
5
|
+
* 命名视图
|
|
6
|
+
*
|
|
7
|
+
* @default 'default'
|
|
8
|
+
*/
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* # 路由器视图
|
|
13
|
+
*
|
|
14
|
+
* 用于渲染路由线路配置的`widget`,可以在子组件中嵌套`RouterView`,但应用内只能存在一个根视图。
|
|
15
|
+
*
|
|
16
|
+
* 如需实现页面缓存等功能,可以重写该类的{@link build}方法。
|
|
17
|
+
*/
|
|
18
|
+
export declare class RouterView extends Widget<RouteOptions> {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(props: RouteOptions);
|
|
21
|
+
/**
|
|
22
|
+
* 当前路由器视图所在层级索引
|
|
23
|
+
*
|
|
24
|
+
* `index`的值从0开始,它与`RouteLocation.matched`数组下标一一对应
|
|
25
|
+
*/
|
|
26
|
+
get index(): number;
|
|
27
|
+
/**
|
|
28
|
+
* 是否为最后一个路由视图
|
|
29
|
+
*/
|
|
30
|
+
get isLastView(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 视图名称
|
|
33
|
+
*
|
|
34
|
+
* @default 'default'
|
|
35
|
+
*/
|
|
36
|
+
get name(): string;
|
|
37
|
+
get matchedRoute(): RouteNormalized | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 当前路由器视图要显示的虚拟节点
|
|
40
|
+
*
|
|
41
|
+
* 注意未匹配时会返回`undefined`,匹配成功时返回的是`VNode<WidgetType>`
|
|
42
|
+
*
|
|
43
|
+
* @protected
|
|
44
|
+
*/
|
|
45
|
+
protected get currentElement(): VNode | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* 当前的路由位置对象
|
|
48
|
+
*
|
|
49
|
+
* @protected
|
|
50
|
+
*/
|
|
51
|
+
protected get location(): Readonly<import('vitarx').Reactive<import('../index.js').RouteLocation>>;
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
55
|
+
protected onMounted(): void;
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
59
|
+
protected onUpdated(): void;
|
|
60
|
+
/**
|
|
61
|
+
* ## 构建视图
|
|
62
|
+
*
|
|
63
|
+
* 可以重写该方法添加自定义的视图元素
|
|
64
|
+
*
|
|
65
|
+
* 例如,使用`KeepAlive`组件缓存当前视图元素:
|
|
66
|
+
* ```tsx
|
|
67
|
+
* protected build() {
|
|
68
|
+
* // 不可省略,因为`KeepAlive`不能渲染非组件节点。
|
|
69
|
+
* if (!this.currentElement) return <></> // 使用空片段节点占位
|
|
70
|
+
*
|
|
71
|
+
* // 将当前显示的视图元素(VNode<WidgetType>对象)传递给`KeepAlive`插槽,使用缓存功能。
|
|
72
|
+
* return <KeepAlive onlyKey={this.matchedRoute?.path}>{this.currentElement}</KeepAlive>
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
* @protected
|
|
76
|
+
*/
|
|
77
|
+
protected build(): Element;
|
|
78
|
+
/**
|
|
79
|
+
* 视图渲染完成通知路由器
|
|
80
|
+
*
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
private completeViewRender;
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './RouterView.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vitarx-router",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/vitarx-router.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite --force",
|
|
9
|
+
"build": "rimraf dist && tsc --p tsconfig-build.json && vite build",
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
12
|
+
"push": "npm publish --access=public"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"vitarx": "^1.0.0-beta.19"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^22.10.0",
|
|
19
|
+
"prettier": "^3.3.1",
|
|
20
|
+
"typescript": "^5.2.2",
|
|
21
|
+
"vite": "^5.2.0",
|
|
22
|
+
"vite-plugin-dts": "^4.3.0",
|
|
23
|
+
"vite-plugin-vitarx": "^1.0.0-beta.13"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"README.md"
|
|
29
|
+
]
|
|
30
|
+
}
|