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.
@@ -0,0 +1,65 @@
1
+ import { default as Router } from './router.js';
2
+ import { RouteLocation, RouterOptions, RouteTarget } from './type.js';
3
+ /**
4
+ * 基于`window.history`实现的路由器
5
+ *
6
+ * 支持浏览器前进、后退、跳转等操作
7
+ */
8
+ export default class WebHistoryRouter extends Router {
9
+ constructor(options: RouterOptions<'path' | 'hash'>);
10
+ /**
11
+ * 当前路由目标
12
+ *
13
+ * @returns {RouteTarget} - 包含 index、hash 和 query 的对象
14
+ */
15
+ protected get currentRouteTarget(): MakeRequired<RouteTarget, 'query' | 'hash'>;
16
+ /**
17
+ * window.history
18
+ *
19
+ * @private
20
+ */
21
+ private get webHistory();
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ go(delta?: number): void;
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ protected initializeRouter(): void;
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ protected pushHistory(data: RouteLocation): void;
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ protected replaceHistory(data: RouteLocation): void;
38
+ /**
39
+ * 保存当前页面滚动位置
40
+ *
41
+ * @private
42
+ */
43
+ private saveCurrentScrollPosition;
44
+ /**
45
+ * 创建历史记录状态
46
+ *
47
+ * 用于在浏览器历史记录中存储路由信息,以支持前进、后退等操作。
48
+ *
49
+ * @param data - 路由数据
50
+ * @param hash - 要替换的哈希值
51
+ * @param query - 要替换的查询参数
52
+ * @private
53
+ */
54
+ private createState;
55
+ /**
56
+ * 处理浏览器历史记录的返回/前进事件
57
+ */
58
+ private onPopState;
59
+ /**
60
+ * 确保路径是 hash 格式
61
+ *
62
+ * @private
63
+ */
64
+ private ensureHash;
65
+ }