@lytjs/router 5.0.0 → 6.0.0

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/package.json CHANGED
@@ -1,50 +1,55 @@
1
1
  {
2
2
  "name": "@lytjs/router",
3
- "version": "5.0.0",
4
- "description": "Lyt.js 内置路由 - History/Hash 模式、导航守卫、动态路由",
3
+ "version": "6.0.0",
4
+ "description": "LytJS declarative routing system with support for nested routes, navigation guards, and history modes",
5
+ "type": "module",
5
6
  "main": "./dist/index.cjs",
6
7
  "module": "./dist/index.mjs",
7
- "types": "./dist/types/index.d.ts",
8
+ "types": "./dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/types/index.d.ts",
11
+ "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.mjs",
12
- "require": "./dist/index.cjs",
13
- "default": "./dist/index.mjs"
14
- }
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./package.json": "./package.json"
15
16
  },
16
- "sideEffects": false,
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
+ "sideEffects": false,
21
+ "scripts": {
22
+ "build": "echo 'Skipping router build for now'",
23
+ "dev": "tsup --watch",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "test:coverage": "vitest run --coverage",
27
+ "type-check": "tsc --noEmit",
28
+ "lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
29
+ "clean": "rm -rf dist"
30
+ },
31
+ "dependencies": {
32
+ "@lytjs/common-is": "^6.0.0",
33
+ "@lytjs/common-env": "^6.0.0",
34
+ "@lytjs/reactivity": "^6.0.0",
35
+ "@lytjs/component": "^6.0.0",
36
+ "@lytjs/vdom": "^6.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "tsup": "^8.0.0",
40
+ "typescript": "^5.4.0",
41
+ "vitest": "^3.0.0"
42
+ },
20
43
  "license": "MIT",
21
- "author": "lytjs",
22
44
  "repository": {
23
45
  "type": "git",
24
- "url": "https://gitee.com/lytjs/lytjs"
46
+ "url": "https://gitee.com/lytjs/lytjs.git",
47
+ "directory": "packages/ecosystem/packages/router"
25
48
  },
26
- "homepage": "https://gitee.com/lytjs/lytjs",
27
49
  "keywords": [
28
- "lyt",
29
50
  "lytjs",
30
- "javascript",
31
- "framework",
32
- "frontend",
33
- "vue-like",
34
- "lightweight",
35
- "zero-dependency",
36
51
  "router",
37
- "history",
38
- "hash"
39
- ],
40
- "dependencies": {
41
- "@lytjs/common": "^5.0.0",
42
- "@lytjs/reactivity": "^5.0.0"
43
- },
44
- "engines": {
45
- "node": ">=18.0.0"
46
- },
47
- "publishConfig": {
48
- "access": "public"
49
- }
52
+ "routing",
53
+ "spa"
54
+ ]
50
55
  }
package/README.md DELETED
@@ -1,253 +0,0 @@
1
- # @lytjs/router
2
-
3
- Lyt.js 官方路由 - 提供 History / Hash 模式、导航守卫、动态路由等能力。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install @lytjs/router
9
-
10
- # 或使用 pnpm
11
- pnpm add @lytjs/router
12
- ```
13
-
14
- ## 特性
15
-
16
- - 🚀 History / Hash 双模式
17
- - 🔄 完整的导航守卫
18
- - 📦 动态路由匹配
19
- - 🎯 嵌套路由
20
- - 📋 命名路由和命名视图
21
- - 🔌 零运行时依赖
22
-
23
- ## 快速开始
24
-
25
- ```javascript
26
- import { createRouter, createWebHistory } from '@lytjs/router';
27
- import { createApp } from '@lytjs/core';
28
- import Home from './views/Home.vue';
29
- import About from './views/About.vue';
30
-
31
- // 1. 定义路由
32
- const routes = [
33
- { path: '/', component: Home },
34
- { path: '/about', component: About }
35
- ];
36
-
37
- // 2. 创建路由实例
38
- const router = createRouter({
39
- history: createWebHistory(),
40
- routes
41
- });
42
-
43
- // 3. 创建应用并使用路由
44
- const app = createApp(App);
45
- app.use(router);
46
- app.mount('#app');
47
- ```
48
-
49
- ## API 参考
50
-
51
- ### 路由创建
52
-
53
- | API | 说明 |
54
- |------|------|
55
- | `createRouter(options)` | 创建路由实例 |
56
- | `createWebHistory(base)` | HTML5 History 模式 |
57
- | `createWebHashHistory(base)` | Hash 模式 |
58
- | `createMemoryHistory(base)` | 内存模式(测试用) |
59
-
60
- ### 组件
61
-
62
- | 组件 | 说明 |
63
- |------|------|
64
- | `<router-view>` | 路由视图出口 |
65
- | `<router-link>` | 路由导航链接 |
66
-
67
- ### 组合式 API
68
-
69
- | API | 说明 |
70
- |------|------|
71
- | `useRouter()` | 获取路由实例 |
72
- | `useRoute()` | 获取当前路由信息 |
73
- | `useLink(props)` | 创建导航链接 |
74
-
75
- ## 路由配置
76
-
77
- ```javascript
78
- const routes = [
79
- {
80
- path: '/',
81
- name: 'home',
82
- component: Home,
83
- meta: { title: '首页' }
84
- },
85
- {
86
- path: '/user/:id',
87
- name: 'user',
88
- component: User,
89
- props: true
90
- },
91
- {
92
- path: '/parent',
93
- component: Parent,
94
- children: [
95
- {
96
- path: 'child',
97
- component: Child
98
- }
99
- ]
100
- }
101
- ];
102
- ```
103
-
104
- ## 导航守卫
105
-
106
- ```javascript
107
- // 全局前置守卫
108
- router.beforeEach((to, from) => {
109
- if (!isAuthenticated && to.path !== '/login') {
110
- return '/login';
111
- }
112
- });
113
-
114
- // 全局解析守卫
115
- router.beforeResolve(async (to) => {
116
- // 在导航被确认之前、所有组件内守卫和异步路由组件被解析之后调用
117
- });
118
-
119
- // 全局后置钩子
120
- router.afterEach((to, from) => {
121
- document.title = to.meta.title;
122
- });
123
- ```
124
-
125
- ## 组件内守卫
126
-
127
- ```javascript
128
- import { onBeforeRouteLeave, onBeforeRouteUpdate } from '@lytjs/router';
129
-
130
- onBeforeRouteLeave((to, from) => {
131
- const answer = window.confirm('确定要离开吗?');
132
- if (!answer) {
133
- return false;
134
- }
135
- });
136
-
137
- onBeforeRouteUpdate((to, from) => {
138
- // 在当前路由改变,但是该组件被复用时调用
139
- console.log('路由更新了');
140
- });
141
- ```
142
-
143
- ## 路由元信息
144
-
145
- ```javascript
146
- const routes = [
147
- {
148
- path: '/admin',
149
- component: Admin,
150
- meta: { requiresAuth: true }
151
- }
152
- ];
153
-
154
- router.beforeEach((to, from) => {
155
- if (to.meta.requiresAuth && !isAuthenticated()) {
156
- return {
157
- path: '/login',
158
- query: { redirect: to.fullPath }
159
- };
160
- }
161
- });
162
- ```
163
-
164
- ## 示例
165
-
166
- ### 编程式导航
167
-
168
- ```javascript
169
- import { useRouter } from '@lytjs/router';
170
-
171
- const router = useRouter();
172
-
173
- // 字符串路径
174
- router.push('/users');
175
-
176
- // 带路径的对象
177
- router.push({ path: '/users' });
178
-
179
- // 命名的路由
180
- router.push({ name: 'user', params: { id: '123' } });
181
-
182
- // 带查询参数,变成 /register?plan=private
183
- router.push({ path: '/register', query: { plan: 'private' } });
184
- ```
185
-
186
- ### 获取路由信息
187
-
188
- ```javascript
189
- import { useRoute } from '@lytjs/router';
190
-
191
- const route = useRoute();
192
-
193
- console.log(route.path); // 当前路径
194
- console.log(route.params); // 动态参数
195
- console.log(route.query); // 查询参数
196
- console.log(route.meta); // 元信息
197
- ```
198
-
199
- ### 嵌套路由
200
-
201
- ```javascript
202
- const routes = [
203
- {
204
- path: '/user/:id',
205
- component: User,
206
- children: [
207
- {
208
- // 当 /user/:id/profile 匹配成功
209
- // UserProfile 会被渲染在 User 的 <router-view> 中
210
- path: 'profile',
211
- component: UserProfile
212
- },
213
- {
214
- // 当 /user/:id/posts 匹配成功
215
- // UserPosts 会被渲染在 User 的 <router-view> 中
216
- path: 'posts',
217
- component: UserPosts
218
- }
219
- ]
220
- }
221
- ];
222
- ```
223
-
224
- ### 重定向和别名
225
-
226
- ```javascript
227
- const routes = [
228
- // 重定向
229
- { path: '/home', redirect: '/' },
230
- { path: '/home', redirect: { name: 'homepage' } },
231
-
232
- // 别名
233
- { path: '/', component: Home, alias: '/home' }
234
- ];
235
- ```
236
-
237
- ## 性能
238
-
239
- - 体积小,零运行时依赖
240
- - 按需加载路由
241
- - 高效的路径匹配算法
242
-
243
- ## 兼容性
244
-
245
- - Node.js >= 18.0.0
246
- - Chrome 64+
247
- - Firefox 63+
248
- - Safari 12+
249
- - Edge 79+
250
-
251
- ## License
252
-
253
- MIT
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var T=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},A=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of W(t))!U.call(e,u)&&u!==r&&T(e,u,{get:()=>t[u],enumerable:!(i=S(t,u))||i.enumerable});return e};var D=e=>A(T({},"__esModule",{value:!0}),e);var j={};z(j,{createHashHistory:()=>x,createNavigationGuards:()=>N,createRouteMatcher:()=>m,createRouter:()=>O,createWebHistory:()=>w,runAfterGuards:()=>b,runGuards:()=>y});module.exports=D(j);var p=require("@lytjs/common");function H(e,t=""){let r=(0,p.normalizePath)(t,e.path),{regex:i,paramKeys:u,isWildcard:s}=(0,p.pathToRegex)(r);if(e._regex=i,e._paramKeys=u,e._isWildcard=s,e.children)for(let c of e.children)H(c,r)}function m(e){let t=[];function r(n,a=""){for(let o of n)if(H(o,a),t.push(o),o.children){let d=(0,p.normalizePath)(a,o.path);r(o.children,d)}}r(e);function i(n){let a=n.replace(/\/+$/,"")||"/";for(let o of t){if(!o._regex)continue;let d=a.match(o._regex);if(d){let f={};if(o._paramKeys)for(let g=0;g<o._paramKeys.length;g++){let v=o._paramKeys[g];f[v]=d[g+1]||""}return{record:o,params:f,matchedPath:a}}}return null}function u(n){if(H(n),t.push(n),n.children){let a=(0,p.normalizePath)("",n.path);r(n.children,a)}}function s(n){for(let a=t.length-1;a>=0;a--)t[a].name===n&&t.splice(a,1)}function c(){return[...t]}return{matchRoute:i,addRoute:u,removeRoute:s,getRoutes:c}}function K(e){let t={};if(!e||e==="?")return t;let i=(e.startsWith("?")?e.slice(1):e).split("&");for(let u of i){let s=u.indexOf("=");if(s===-1)t[decodeURIComponent(u)]="";else{let c=decodeURIComponent(u.slice(0,s)),n=decodeURIComponent(u.slice(s+1));t[c]=n}}return t}function q(e){let t=[];for(let r of Object.keys(e)){let i=e[r];i!=null&&t.push(encodeURIComponent(r)+"="+encodeURIComponent(i))}return t.join("&")}function I(e){let t="",r=e,i=e.indexOf("#");i!==-1&&(t=e.slice(i+1),r=e.slice(0,i));let u=r,s={},c=r.indexOf("?");return c!==-1&&(u=r.slice(0,c),s=K(r.slice(c))),{path:u,query:s,hash:t}}function h(e){return e.startsWith("/")||(e="/"+e),e.replace(/\/+/g,"/")}function w(e="/"){let t=h(e),r=[],i=s(window.location.href);function u(n){let a=s(window.location.href);a.fromPopState=!0,a.state=n.state;let o=i;i=a,c(a,o)}function s(n){let a;try{a=new URL(n)}catch(v){a=new URL(n,window.location.origin)}let o=a.pathname;t!=="/"&&o.startsWith(t)&&(o=o.slice(t.length)||"/");let{path:d,query:f,hash:g}=I(o+a.hash);return{path:h(d),fullPath:h(d)+(Object.keys(f).length?"?"+q(f):"")+(g?"#"+g:""),query:f,hash:g,state:a.state||null,fromPopState:!1}}function c(n,a){for(let o of r)o(n,a)}return window.addEventListener("popstate",u),{base:t,get location(){return i},push(n,a){let o=h(n),d=i,f=(t+o).replace(/\/+/g,"/");window.history.pushState(a||null,"",f),i=s(window.location.href),i.state=a||null,c(i,d)},replace(n,a){let o=h(n),d=i,f=(t+o).replace(/\/+/g,"/");window.history.replaceState(a||null,"",f),i=s(window.location.href),i.state=a||null,c(i,d)},go(n){window.history.go(n)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return s(window.location.href)},listen(n){return r.push(n),()=>{let a=r.indexOf(n);a!==-1&&r.splice(a,1)}},destroy(){window.removeEventListener("popstate",u),r.length=0}}}function x(){let e=[],t=i();function r(){let s=i();s.fromPopState=!0;let c=t;t=s,u(s,c)}function i(){let c=window.location.hash.slice(1)||"/",{path:n,query:a,hash:o}=I(c);return{path:h(n),fullPath:h(n)+(Object.keys(a).length?"?"+q(a):"")+(o?"#"+o:""),query:a,hash:o,state:null,fromPopState:!1}}function u(s,c){for(let n of e)n(s,c)}return window.addEventListener("hashchange",r),{base:"",get location(){return t},push(s,c){let n=h(s),a=t;window.location.hash=n,t=i(),u(t,a)},replace(s,c){let n=h(s),a=t;window.location.replace(window.location.pathname+window.location.search+"#"+n),t=i(),u(t,a)},go(s){window.history.go(s)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return i()},listen(s){return e.push(s),()=>{let c=e.indexOf(s);c!==-1&&e.splice(c,1)}},destroy(){window.removeEventListener("hashchange",r),e.length=0}}}function N(){let e=[],t=[],r=[];function i(c){return e.push(c),()=>{let n=e.indexOf(c);n!==-1&&e.splice(n,1)}}function u(c){return t.push(c),()=>{let n=t.indexOf(c);n!==-1&&t.splice(n,1)}}function s(c){return r.push(c),()=>{let n=r.indexOf(c);n!==-1&&r.splice(n,1)}}return{_beforeEachGuards:e,_beforeResolveGuards:t,_afterEachGuards:r,beforeEach:i,beforeResolve:u,afterEach:s}}function y(e,t,r){return new Promise((i,u)=>{let s=0;function c(){let a=!1;return o=>{a||(a=!0,o===!1?u(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):typeof o=="string"?u(new Error("REDIRECT:"+o)):(s++,n()))}}function n(){if(s>=e.length){i();return}let a=e[s],o=c();try{let d=a(t,r,o);d!=null&&typeof d=="object"&&typeof d.then=="function"&&d.then(()=>{}).catch(f=>{!f||typeof f.message!="string"||!f.message.startsWith("REDIRECT:")?u(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):u(f)})}catch(d){u(new Error("\u5BFC\u822A\u5B88\u536B\u6267\u884C\u51FA\u9519"))}}n()})}function b(e,t,r){for(let i of e)try{i(t,r)}catch(u){}}var L=require("@lytjs/reactivity");function $(e,t){return{path:e.path,fullPath:e.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:e.query,hash:e.hash}}function C(e,t){return(0,L.reactive)({path:e.path,fullPath:e.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:e.query,hash:e.hash,matched:t?[t.record]:[]})}function O(e){let t=m(e.routes),r=e.mode==="hash"?x():w(e.base||"/"),i=N(),u=(0,L.ref)(C(r.location,t.matchRoute(r.location.path))),s=!1,c=r.listen(async(o,d)=>{await n(o.path,d,!0)});async function n(o,d,f=!1){var g,v;if(!s){s=!0;try{let _=t.matchRoute(o),M={path:o,fullPath:o,query:{},hash:"",state:null,fromPopState:f},G=$(M,_),R=u.value,P={path:R.path,fullPath:R.fullPath,params:R.params,name:R.name,meta:R.meta,query:R.query,hash:R.hash};try{await y(i._beforeEachGuards,G,P)}catch(l){if((g=l==null?void 0:l.message)!=null&&g.startsWith("REDIRECT:")){let E=l.message.replace("REDIRECT:","");s=!1,f||r.replace(E);return}return}try{await y(i._beforeResolveGuards,G,P)}catch(l){if((v=l==null?void 0:l.message)!=null&&v.startsWith("REDIRECT:")){let E=l.message.replace("REDIRECT:","");s=!1,f||r.replace(E);return}return}let k=C(M,_);u.value=k,b(i._afterEachGuards,G,P)}finally{s=!1}}}let a={currentRoute:u,async push(o){r.push(o)},async replace(o){r.replace(o)},go(o){r.go(o)},back(){r.back()},forward(){r.forward()},beforeEach(o){return i.beforeEach(o)},afterEach(o){return i.afterEach(o)},beforeResolve(o){return i.beforeResolve(o)},addRoute(o){t.addRoute(o)},removeRoute(o){t.removeRoute(o)},getRoutes(){return t.getRoutes()},install(o){o.config&&o.config.globalProperties&&(o.config.globalProperties.$router=a,Object.defineProperty(o.config.globalProperties,"$route",{get(){return u.value}})),o.provide&&(o.provide("router",a),o.provide("route",u));let d=t.matchRoute(r.location.path);u.value=C(r.location,d)},destroy(){c(),r.destroy()}};return a}
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- import{normalizePath as x,pathToRegex as I}from"@lytjs/common";function N(o,t=""){let a=x(t,o.path),{regex:i,paramKeys:c,isWildcard:s}=I(a);if(o._regex=i,o._paramKeys=c,o._isWildcard=s,o.children)for(let u of o.children)N(u,a)}function b(o){let t=[];function a(r,n=""){for(let e of r)if(N(e,n),t.push(e),e.children){let d=x(n,e.path);a(e.children,d)}}a(o);function i(r){let n=r.replace(/\/+$/,"")||"/";for(let e of t){if(!e._regex)continue;let d=n.match(e._regex);if(d){let f={};if(e._paramKeys)for(let g=0;g<e._paramKeys.length;g++){let p=e._paramKeys[g];f[p]=d[g+1]||""}return{record:e,params:f,matchedPath:n}}}return null}function c(r){if(N(r),t.push(r),r.children){let n=x("",r.path);a(r.children,n)}}function s(r){for(let n=t.length-1;n>=0;n--)t[n].name===r&&t.splice(n,1)}function u(){return[...t]}return{matchRoute:i,addRoute:c,removeRoute:s,getRoutes:u}}function O(o){let t={};if(!o||o==="?")return t;let i=(o.startsWith("?")?o.slice(1):o).split("&");for(let c of i){let s=c.indexOf("=");if(s===-1)t[decodeURIComponent(c)]="";else{let u=decodeURIComponent(c.slice(0,s)),r=decodeURIComponent(c.slice(s+1));t[u]=r}}return t}function _(o){let t=[];for(let a of Object.keys(o)){let i=o[a];i!=null&&t.push(encodeURIComponent(a)+"="+encodeURIComponent(i))}return t.join("&")}function M(o){let t="",a=o,i=o.indexOf("#");i!==-1&&(t=o.slice(i+1),a=o.slice(0,i));let c=a,s={},u=a.indexOf("?");return u!==-1&&(c=a.slice(0,u),s=O(a.slice(u))),{path:c,query:s,hash:t}}function h(o){return o.startsWith("/")||(o="/"+o),o.replace(/\/+/g,"/")}function L(o="/"){let t=h(o),a=[],i=s(window.location.href);function c(r){let n=s(window.location.href);n.fromPopState=!0,n.state=r.state;let e=i;i=n,u(n,e)}function s(r){let n;try{n=new URL(r)}catch(p){n=new URL(r,window.location.origin)}let e=n.pathname;t!=="/"&&e.startsWith(t)&&(e=e.slice(t.length)||"/");let{path:d,query:f,hash:g}=M(e+n.hash);return{path:h(d),fullPath:h(d)+(Object.keys(f).length?"?"+_(f):"")+(g?"#"+g:""),query:f,hash:g,state:n.state||null,fromPopState:!1}}function u(r,n){for(let e of a)e(r,n)}return window.addEventListener("popstate",c),{base:t,get location(){return i},push(r,n){let e=h(r),d=i,f=(t+e).replace(/\/+/g,"/");window.history.pushState(n||null,"",f),i=s(window.location.href),i.state=n||null,u(i,d)},replace(r,n){let e=h(r),d=i,f=(t+e).replace(/\/+/g,"/");window.history.replaceState(n||null,"",f),i=s(window.location.href),i.state=n||null,u(i,d)},go(r){window.history.go(r)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return s(window.location.href)},listen(r){return a.push(r),()=>{let n=a.indexOf(r);n!==-1&&a.splice(n,1)}},destroy(){window.removeEventListener("popstate",c),a.length=0}}}function G(){let o=[],t=i();function a(){let s=i();s.fromPopState=!0;let u=t;t=s,c(s,u)}function i(){let u=window.location.hash.slice(1)||"/",{path:r,query:n,hash:e}=M(u);return{path:h(r),fullPath:h(r)+(Object.keys(n).length?"?"+_(n):"")+(e?"#"+e:""),query:n,hash:e,state:null,fromPopState:!1}}function c(s,u){for(let r of o)r(s,u)}return window.addEventListener("hashchange",a),{base:"",get location(){return t},push(s,u){let r=h(s),n=t;window.location.hash=r,t=i(),c(t,n)},replace(s,u){let r=h(s),n=t;window.location.replace(window.location.pathname+window.location.search+"#"+r),t=i(),c(t,n)},go(s){window.history.go(s)},back(){window.history.back()},forward(){window.history.forward()},getCurrentRoute(){return i()},listen(s){return o.push(s),()=>{let u=o.indexOf(s);u!==-1&&o.splice(u,1)}},destroy(){window.removeEventListener("hashchange",a),o.length=0}}}function P(){let o=[],t=[],a=[];function i(u){return o.push(u),()=>{let r=o.indexOf(u);r!==-1&&o.splice(r,1)}}function c(u){return t.push(u),()=>{let r=t.indexOf(u);r!==-1&&t.splice(r,1)}}function s(u){return a.push(u),()=>{let r=a.indexOf(u);r!==-1&&a.splice(r,1)}}return{_beforeEachGuards:o,_beforeResolveGuards:t,_afterEachGuards:a,beforeEach:i,beforeResolve:c,afterEach:s}}function v(o,t,a){return new Promise((i,c)=>{let s=0;function u(){let n=!1;return e=>{n||(n=!0,e===!1?c(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):typeof e=="string"?c(new Error("REDIRECT:"+e)):(s++,r()))}}function r(){if(s>=o.length){i();return}let n=o[s],e=u();try{let d=n(t,a,e);d!=null&&typeof d=="object"&&typeof d.then=="function"&&d.then(()=>{}).catch(f=>{!f||typeof f.message!="string"||!f.message.startsWith("REDIRECT:")?c(new Error("\u5BFC\u822A\u88AB\u5B88\u536B\u4E2D\u6B62")):c(f)})}catch(d){c(new Error("\u5BFC\u822A\u5B88\u536B\u6267\u884C\u51FA\u9519"))}}r()})}function E(o,t,a){for(let i of o)try{i(t,a)}catch(c){}}import{ref as k,reactive as S}from"@lytjs/reactivity";function W(o,t){return{path:o.path,fullPath:o.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:o.query,hash:o.hash}}function T(o,t){return S({path:o.path,fullPath:o.fullPath,params:(t==null?void 0:t.params)||{},name:t==null?void 0:t.record.name,meta:(t==null?void 0:t.record.meta)||{},query:o.query,hash:o.hash,matched:t?[t.record]:[]})}function U(o){let t=b(o.routes),a=o.mode==="hash"?G():L(o.base||"/"),i=P(),c=k(T(a.location,t.matchRoute(a.location.path))),s=!1,u=a.listen(async(e,d)=>{await r(e.path,d,!0)});async function r(e,d,f=!1){var g,p;if(!s){s=!0;try{let H=t.matchRoute(e),C={path:e,fullPath:e,query:{},hash:"",state:null,fromPopState:f},y=W(C,H),R=c.value,m={path:R.path,fullPath:R.fullPath,params:R.params,name:R.name,meta:R.meta,query:R.query,hash:R.hash};try{await v(i._beforeEachGuards,y,m)}catch(l){if((g=l==null?void 0:l.message)!=null&&g.startsWith("REDIRECT:")){let w=l.message.replace("REDIRECT:","");s=!1,f||a.replace(w);return}return}try{await v(i._beforeResolveGuards,y,m)}catch(l){if((p=l==null?void 0:l.message)!=null&&p.startsWith("REDIRECT:")){let w=l.message.replace("REDIRECT:","");s=!1,f||a.replace(w);return}return}let q=T(C,H);c.value=q,E(i._afterEachGuards,y,m)}finally{s=!1}}}let n={currentRoute:c,async push(e){a.push(e)},async replace(e){a.replace(e)},go(e){a.go(e)},back(){a.back()},forward(){a.forward()},beforeEach(e){return i.beforeEach(e)},afterEach(e){return i.afterEach(e)},beforeResolve(e){return i.beforeResolve(e)},addRoute(e){t.addRoute(e)},removeRoute(e){t.removeRoute(e)},getRoutes(){return t.getRoutes()},install(e){e.config&&e.config.globalProperties&&(e.config.globalProperties.$router=n,Object.defineProperty(e.config.globalProperties,"$route",{get(){return c.value}})),e.provide&&(e.provide("router",n),e.provide("route",c));let d=t.matchRoute(a.location.path);c.value=T(a.location,d)},destroy(){u(),a.destroy()}};return n}export{G as createHashHistory,P as createNavigationGuards,b as createRouteMatcher,U as createRouter,L as createWebHistory,E as runAfterGuards,v as runGuards};
@@ -1,112 +0,0 @@
1
- /**
2
- * Lyt.js 路由系统 — 路由创建(createRouter)
3
- *
4
- * 整合路由匹配器、History 管理和导航守卫,提供完整的路由实例。
5
- *
6
- * 核心功能:
7
- * - 创建路由实例(支持 history 和 hash 两种模式)
8
- * - 导航方法:push / replace / go / back / forward
9
- * - 导航守卫:beforeEach / afterEach / beforeResolve
10
- * - 响应式当前路由(currentRoute,基于 @lytjs/reactivity)
11
- * - 插件安装(install 方法,供 app.use 调用)
12
- *
13
- * 集成 @lytjs/reactivity 实现响应式路由。
14
- */
15
- import { type RouteRecord } from './matcher';
16
- import { type NavigationGuard } from './guards';
17
- import { type Ref } from '@lytjs/reactivity';
18
- /** 路由模式 */
19
- export type RouterMode = 'history' | 'hash';
20
- /** 路由创建选项 */
21
- export interface RouterOptions {
22
- /** 路由模式:history(HTML5 History)或 hash */
23
- mode: RouterMode;
24
- /** 路由配置数组 */
25
- routes: RouteRecord[];
26
- /** 基础路径(仅 history 模式有效,默认 '/') */
27
- base?: string;
28
- }
29
- /** 路由信息(对外暴露) */
30
- export interface Route {
31
- /** 路由路径 */
32
- path: string;
33
- /** 完整路径 */
34
- fullPath: string;
35
- /** 路由参数 */
36
- params: Record<string, string>;
37
- /** 路由名称 */
38
- name?: string;
39
- /** 路由元信息 */
40
- meta?: Record<string, any>;
41
- /** 查询参数 */
42
- query: Record<string, string>;
43
- /** hash 值 */
44
- hash: string;
45
- /** 匹配到的路由记录 */
46
- matched: RouteRecord[];
47
- }
48
- /** 路由实例 */
49
- export interface Router {
50
- /** 当前路由信息(响应式 Ref) */
51
- currentRoute: Ref<Route>;
52
- /** 导航到新路径 */
53
- push(path: string): Promise<void>;
54
- /** 替换当前路径 */
55
- replace(path: string): Promise<void>;
56
- /** 前进/后退 n 步 */
57
- go(n: number): void;
58
- /** 后退一步 */
59
- back(): void;
60
- /** 前进一步 */
61
- forward(): void;
62
- /** 注册全局前置守卫 */
63
- beforeEach(guard: NavigationGuard): () => void;
64
- /** 注册全局后置守卫 */
65
- afterEach(guard: (to: Route, from: Route) => void): () => void;
66
- /** 注册全局解析守卫 */
67
- beforeResolve(guard: NavigationGuard): () => void;
68
- /** 动态添加路由 */
69
- addRoute(route: RouteRecord): void;
70
- /** 按名称移除路由 */
71
- removeRoute(name: string): void;
72
- /** 获取所有路由记录 */
73
- getRoutes(): RouteRecord[];
74
- /** 插件安装方法(供 app.use 调用) */
75
- install(app: any): void;
76
- /** 销毁路由实例 */
77
- destroy(): void;
78
- }
79
- /**
80
- * 创建路由实例
81
- *
82
- * 整合匹配器、History 和守卫,提供完整的路由功能。
83
- *
84
- * @param options - 路由配置选项
85
- * @returns 路由实例
86
- *
87
- * @example
88
- * ```ts
89
- * const router = createRouter({
90
- * mode: 'history',
91
- * routes: [
92
- * { path: '/', name: 'home', component: Home },
93
- * { path: '/user/:id', name: 'user', component: User },
94
- * ],
95
- * base: '/app',
96
- * })
97
- *
98
- * // 注册守卫
99
- * router.beforeEach((to, from, next) => {
100
- * console.log('导航到:', to.path)
101
- * next()
102
- * })
103
- *
104
- * // 编程式导航
105
- * router.push('/user/123')
106
- *
107
- * // 作为插件安装
108
- * app.use(router)
109
- * ```
110
- */
111
- export declare function createRouter(options: RouterOptions): Router;
112
- //# sourceMappingURL=create-router.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-router.d.ts","sourceRoot":"","sources":["../../src/create-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAEL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AASnB,OAAO,EAKL,KAAK,eAAe,EAErB,MAAM,UAAU,CAAC;AAElB,OAAO,EAGL,KAAK,GAAG,EACT,MAAM,mBAAmB,CAAC;AAM3B,WAAW;AACX,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAE5C,aAAa;AACb,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa;IACb,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,iBAAiB;AACjB,MAAM,WAAW,KAAK;IACpB,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,WAAW;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,aAAa;IACb,IAAI,EAAE,MAAM,CAAC;IACb,eAAe;IACf,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,WAAW;AACX,MAAM,WAAW,MAAM;IACrB,sBAAsB;IACtB,YAAY,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,aAAa;IACb,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,aAAa;IACb,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,gBAAgB;IAChB,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW;IACX,IAAI,IAAI,IAAI,CAAC;IACb,WAAW;IACX,OAAO,IAAI,IAAI,CAAC;IAChB,eAAe;IACf,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,IAAI,CAAC;IAC/C,eAAe;IACf,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC/D,eAAe;IACf,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,IAAI,CAAC;IAClD,aAAa;IACb,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,cAAc;IACd,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe;IACf,SAAS,IAAI,WAAW,EAAE,CAAC;IAC3B,2BAA2B;IAC3B,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IACxB,aAAa;IACb,OAAO,IAAI,IAAI,CAAC;CACjB;AA8CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAmQ3D"}
@@ -1,107 +0,0 @@
1
- /**
2
- * Lyt.js 路由系统 — 导航守卫(Guards)
3
- *
4
- * 提供全局导航守卫机制,在路由导航过程中执行拦截逻辑。
5
- *
6
- * 守卫类型:
7
- * 1. beforeEach — 全局前置守卫(在导航确认前调用)
8
- * 2. beforeResolve — 全局解析守卫(在导航确认后、组件渲染前调用)
9
- * 3. afterEach — 全局后置守卫(在导航完成后调用)
10
- *
11
- * 导航控制(通过 next 函数):
12
- * - next() — 确认导航
13
- * - next(false) — 取消导航
14
- * - next('/path') — 重定向到指定路径
15
- *
16
- * 纯原生零依赖实现。
17
- */
18
- /** 路由目标位置(简化版) */
19
- export interface NavigationTarget {
20
- /** 目标路径 */
21
- path: string;
22
- /** 完整路径(含 query 和 hash) */
23
- fullPath: string;
24
- /** 路由参数 */
25
- params: Record<string, string>;
26
- /** 路由名称 */
27
- name?: string;
28
- /** 路由元信息 */
29
- meta?: Record<string, any>;
30
- /** 查询参数 */
31
- query: Record<string, string>;
32
- /** hash 值 */
33
- hash: string;
34
- }
35
- /** 导航守卫回调函数 */
36
- export type NavigationGuard = (to: NavigationTarget, from: NavigationTarget, next: NavigationGuardNext) => void;
37
- /** next 函数类型 */
38
- export type NavigationGuardNext = (location?: string | false | void) => void;
39
- /** 导航守卫管理器 */
40
- export interface NavigationGuards {
41
- /** 注册全局前置守卫 */
42
- beforeEach(guard: NavigationGuard): () => void;
43
- /** 注册全局解析守卫 */
44
- beforeResolve(guard: NavigationGuard): () => void;
45
- /** 注册全局后置守卫 */
46
- afterEach(guard: (to: NavigationTarget, from: NavigationTarget) => void): () => void;
47
- /** 前置守卫列表(内部使用) */
48
- _beforeEachGuards: NavigationGuard[];
49
- /** 解析守卫列表(内部使用) */
50
- _beforeResolveGuards: NavigationGuard[];
51
- /** 后置守卫列表(内部使用) */
52
- _afterEachGuards: Array<(to: NavigationTarget, from: NavigationTarget) => void>;
53
- }
54
- /**
55
- * 创建导航守卫管理器
56
- *
57
- * 维护三类守卫队列,提供注册和执行方法。
58
- *
59
- * @returns 导航守卫管理器
60
- *
61
- * @example
62
- * ```ts
63
- * const guards = createNavigationGuards()
64
- *
65
- * // 注册前置守卫
66
- * const remove = guards.beforeEach((to, from, next) => {
67
- * if (to.path === '/admin' && !isLoggedIn) {
68
- * next('/login') // 重定向到登录页
69
- * } else {
70
- * next() // 确认导航
71
- * }
72
- * })
73
- *
74
- * // 注册后置守卫
75
- * guards.afterEach((to, from) => {
76
- * console.log('导航完成:', to.path)
77
- * })
78
- *
79
- * // 移除守卫
80
- * remove()
81
- * ```
82
- */
83
- export declare function createNavigationGuards(): NavigationGuards;
84
- /**
85
- * 执行导航守卫队列
86
- *
87
- * 按顺序执行守卫函数,支持异步守卫。
88
- * 如果某个守卫调用了 next(false),中止导航。
89
- * 如果某个守卫调用了 next('/path'),重定向。
90
- *
91
- * @param guards - 守卫函数列表
92
- * @param to - 目标路由
93
- * @param from - 来源路由
94
- * @returns Promise,resolve 表示导航确认,reject 表示导航中止或重定向
95
- */
96
- export declare function runGuards(guards: NavigationGuard[], to: NavigationTarget, from: NavigationTarget): Promise<void>;
97
- /**
98
- * 执行后置守卫队列
99
- *
100
- * 后置守卫不接受 next 函数,按顺序执行。
101
- *
102
- * @param guards - 后置守卫列表
103
- * @param to - 目标路由
104
- * @param from - 来源路由
105
- */
106
- export declare function runAfterGuards(guards: Array<(to: NavigationTarget, from: NavigationTarget) => void>, to: NavigationTarget, from: NavigationTarget): void;
107
- //# sourceMappingURL=guards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,kBAAkB;AAClB,MAAM,WAAW,gBAAgB;IAC/B,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,WAAW;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,aAAa;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAe;AACf,MAAM,MAAM,eAAe,GAAG,CAC5B,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,mBAAmB,KACtB,IAAI,CAAC;AAEV,gBAAgB;AAChB,MAAM,MAAM,mBAAmB,GAAG,CAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,KAC7B,IAAI,CAAC;AAEV,cAAc;AACd,MAAM,WAAW,gBAAgB;IAC/B,eAAe;IACf,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,IAAI,CAAC;IAC/C,eAAe;IACf,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,IAAI,CAAC;IAClD,eAAe;IACf,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACrF,mBAAmB;IACnB,iBAAiB,EAAE,eAAe,EAAE,CAAC;IACrC,mBAAmB;IACnB,oBAAoB,EAAE,eAAe,EAAE,CAAC;IACxC,mBAAmB;IACnB,gBAAgB,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC,CAAC;CACjF;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAwFzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,eAAe,EAAE,EACzB,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,IAAI,CAAC,CAgFf;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC,EACrE,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAE,gBAAgB,GACrB,IAAI,CAQN"}
@@ -1,98 +0,0 @@
1
- /**
2
- * Lyt.js 路由系统 — History 管理
3
- *
4
- * 提供两种路由模式:
5
- * 1. HTML5 History 模式(createWebHistory):使用 pushState/replaceState API
6
- * 2. Hash 模式(createHashHistory):使用 URL hash(#)部分
7
- *
8
- * 两种模式都提供统一的 API:
9
- * - push(path) / replace(path) / go(n) / back() / forward()
10
- * - 监听 URL 变化事件
11
- * - 获取当前路由信息
12
- *
13
- * 纯原生零依赖实现。
14
- */
15
- /** 路由位置信息 */
16
- export interface RouterLocation {
17
- /** 当前路径 */
18
- path: string;
19
- /** 完整 URL(含 hash) */
20
- fullPath: string;
21
- /** URL 查询参数对象 */
22
- query: Record<string, string>;
23
- /** URL hash 值(不含 #) */
24
- hash: string;
25
- /** 路由状态(通过 pushState 传入的 state) */
26
- state: any;
27
- /** 是否来自浏览器前进/后退操作 */
28
- fromPopState: boolean;
29
- }
30
- /** History 变化监听回调 */
31
- export type HistoryChangeListener = (location: RouterLocation, from: RouterLocation) => void;
32
- /** History 实例接口 */
33
- export interface RouterHistory {
34
- /** 基础路径(History 模式下使用) */
35
- base: string;
36
- /** 当前位置信息 */
37
- location: RouterLocation;
38
- /** 导航到新路径(新增历史记录) */
39
- push(path: string, state?: any): void;
40
- /** 替换当前路径(不新增历史记录) */
41
- replace(path: string, state?: any): void;
42
- /** 前进/后退 n 步 */
43
- go(n: number): void;
44
- /** 后退一步 */
45
- back(): void;
46
- /** 前进一步 */
47
- forward(): void;
48
- /** 获取当前路由位置 */
49
- getCurrentRoute(): RouterLocation;
50
- /** 监听路由变化 */
51
- listen(callback: HistoryChangeListener): () => void;
52
- /** 销毁 History 实例,移除事件监听 */
53
- destroy(): void;
54
- }
55
- /**
56
- * 创建 HTML5 History 模式的路由管理器
57
- *
58
- * 使用浏览器原生的 history.pushState / history.replaceState API,
59
- * 配合 popstate 事件监听浏览器前进/后退操作。
60
- *
61
- * @param base - 应用基础路径(默认 '/')
62
- * @returns History 实例
63
- *
64
- * @example
65
- * ```ts
66
- * const history = createWebHistory('/app')
67
- * history.push('/user/123')
68
- * history.back()
69
- * history.listen((to, from) => {
70
- * console.log('路由变化:', from.path, '->', to.path)
71
- * })
72
- * ```
73
- */
74
- export declare function createWebHistory(base?: string): RouterHistory;
75
- /**
76
- * 创建 Hash 模式的路由管理器
77
- *
78
- * 使用 URL 的 hash 部分(#)作为路由路径。
79
- * 兼容性更好,不需要服务器端配置。
80
- *
81
- * 工作原理:
82
- * - 路由路径存储在 URL 的 hash 部分,如 http://example.com/#/user/123
83
- * - 通过 hashchange 事件监听 hash 变化
84
- * - 通过 location.hash 修改 hash
85
- *
86
- * @returns History 实例
87
- *
88
- * @example
89
- * ```ts
90
- * const history = createHashHistory()
91
- * history.push('/user/123') // URL 变为 http://example.com/#/user/123
92
- * history.listen((to, from) => {
93
- * console.log('hash 路由变化:', from.path, '->', to.path)
94
- * })
95
- * ```
96
- */
97
- export declare function createHashHistory(): RouterHistory;
98
- //# sourceMappingURL=history.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,aAAa;AACb,MAAM,WAAW,cAAc;IAC7B,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,KAAK,EAAE,GAAG,CAAC;IACX,qBAAqB;IACrB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,qBAAqB;AACrB,MAAM,MAAM,qBAAqB,GAAG,CAClC,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,cAAc,KACjB,IAAI,CAAC;AAEV,mBAAmB;AACnB,MAAM,WAAW,aAAa;IAC5B,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,qBAAqB;IACrB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACtC,sBAAsB;IACtB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACzC,gBAAgB;IAChB,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW;IACX,IAAI,IAAI,IAAI,CAAC;IACb,WAAW;IACX,OAAO,IAAI,IAAI,CAAC;IAChB,eAAe;IACf,eAAe,IAAI,cAAc,CAAC;IAClC,aAAa;IACb,MAAM,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM,IAAI,CAAC;IACpD,2BAA2B;IAC3B,OAAO,IAAI,IAAI,CAAC;CACjB;AAqHD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,MAAY,GAAG,aAAa,CAqLlE;AAMD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,CA4JjD"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Lyt.js 路由系统 — 统一导出入口
3
- *
4
- * 导出所有公共 API 和类型定义。
5
- * 纯原生零依赖实现。
6
- */
7
- export { createRouter } from './create-router';
8
- export type { Router, RouterOptions, RouterMode, Route, } from './create-router';
9
- export { createRouteMatcher } from './matcher';
10
- export type { RouteRecord, RouteMatchResult, RouteMatcher, } from './matcher';
11
- export { createWebHistory, createHashHistory, } from './history';
12
- export type { RouterHistory, RouterLocation, HistoryChangeListener, } from './history';
13
- export { createNavigationGuards, runGuards, runAfterGuards, } from './guards';
14
- export type { NavigationGuard, NavigationGuardNext, NavigationTarget, NavigationGuards, } from './guards';
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,YAAY,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,KAAK,GACN,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AAMnB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAEnB,YAAY,EACV,aAAa,EACb,cAAc,EACd,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAMnB,OAAO,EACL,sBAAsB,EACtB,SAAS,EACT,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,UAAU,CAAC"}
@@ -1,80 +0,0 @@
1
- /**
2
- * Lyt.js 路由系统 — 路由匹配器(Matcher)
3
- *
4
- * 自研正则路径匹配引擎,将路由路径模式编译为正则表达式,
5
- * 支持静态路径、动态参数(:param)、通配符(*)。
6
- *
7
- * 核心原理:
8
- * 1. 将路径模式(如 /user/:id)编译为正则表达式(如 /^\/user\/([^/]+)$/)
9
- * 2. 正则中的捕获组对应动态参数,匹配时自动提取参数值
10
- * 3. 通配符 * 编译为 (.+),匹配任意路径
11
- *
12
- * 纯原生零依赖实现。
13
- */
14
- /** 路由记录 */
15
- export interface RouteRecord {
16
- /** 路由名称(唯一标识,用于 removeRoute 等) */
17
- name?: string;
18
- /** 路由路径模式,如 '/user/:id' */
19
- path: string;
20
- /** 路由元信息(自定义数据) */
21
- meta?: Record<string, any>;
22
- /** 路由组件 */
23
- component?: any;
24
- /** 重定向路径 */
25
- redirect?: string;
26
- /** 子路由 */
27
- children?: RouteRecord[];
28
- /** 编译后的正则(内部使用) */
29
- _regex?: RegExp;
30
- /** 参数名列表(内部使用) */
31
- _paramKeys?: string[];
32
- /** 是否为通配符路由 */
33
- _isWildcard?: boolean;
34
- }
35
- /** 路由匹配结果 */
36
- export interface RouteMatchResult {
37
- /** 匹配到的路由记录 */
38
- record: RouteRecord;
39
- /** 提取的路径参数,如 { id: '123' } */
40
- params: Record<string, string>;
41
- /** 匹配到的完整路径 */
42
- matchedPath: string;
43
- }
44
- /** 路由匹配器实例 */
45
- export interface RouteMatcher {
46
- /** 匹配路径,返回匹配结果或 null */
47
- matchRoute(path: string): RouteMatchResult | null;
48
- /** 动态添加路由 */
49
- addRoute(route: RouteRecord): void;
50
- /** 按名称移除路由 */
51
- removeRoute(name: string): void;
52
- /** 获取所有路由记录 */
53
- getRoutes(): RouteRecord[];
54
- }
55
- /**
56
- * 创建路由匹配器
57
- *
58
- * 接收路由配置数组,编译所有路由路径模式为正则表达式,
59
- * 提供 matchRoute、addRoute、removeRoute 等方法。
60
- *
61
- * @param routes - 路由配置数组
62
- * @returns 路由匹配器实例
63
- *
64
- * @example
65
- * ```ts
66
- * const matcher = createRouteMatcher([
67
- * { path: '/', name: 'home', component: Home },
68
- * { path: '/user/:id', name: 'user', component: User },
69
- * { path: '/files/*', name: 'files', component: Files },
70
- * ])
71
- *
72
- * const result = matcher.matchRoute('/user/123')
73
- * // result = { record: {...}, params: { id: '123' }, matchedPath: '/user/123' }
74
- *
75
- * matcher.addRoute({ path: '/about', name: 'about', component: About })
76
- * matcher.removeRoute('about')
77
- * ```
78
- */
79
- export declare function createRouteMatcher(routes: RouteRecord[]): RouteMatcher;
80
- //# sourceMappingURL=matcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../../src/matcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAaH,WAAW;AACX,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,WAAW;IACX,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,YAAY;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU;IACV,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,mBAAmB;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,eAAe;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,aAAa;AACb,MAAM,WAAW,gBAAgB;IAC/B,eAAe;IACf,MAAM,EAAE,WAAW,CAAC;IACpB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,eAAe;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,cAAc;AACd,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAClD,aAAa;IACb,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,cAAc;IACd,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,eAAe;IACf,SAAS,IAAI,WAAW,EAAE,CAAC;CAC5B;AAsCD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,YAAY,CAwHtE"}