@lytjs/router-fs 6.5.0 → 6.7.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/README.md +80 -80
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
# @lytjs/router-fs
|
|
2
|
-
|
|
3
|
-
LytJS 文件系统路由引擎,自动扫描文件系统生成路由配置。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm add @lytjs/router-fs
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## 快速开始
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { createFileSystemRouter } from '@lytjs/router-fs';
|
|
15
|
-
|
|
16
|
-
const router = createFileSystemRouter({
|
|
17
|
-
pagesDir: './src/pages',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// 添加路由
|
|
21
|
-
router.addRoute({
|
|
22
|
-
path: '/about',
|
|
23
|
-
componentPath: './src/pages/about.ts',
|
|
24
|
-
isDynamic: false,
|
|
25
|
-
isNested: false,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// 匹配路由
|
|
29
|
-
const match = router.match('/about');
|
|
30
|
-
console.log(match); // { path: '/about', ... }
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 特性
|
|
34
|
-
|
|
35
|
-
- 基于文件系统的自动路由生成
|
|
36
|
-
- 支持动态路由参数
|
|
37
|
-
- 支持嵌套路由
|
|
38
|
-
- 零外部依赖
|
|
39
|
-
|
|
40
|
-
## API
|
|
41
|
-
|
|
42
|
-
### createFileSystemRouter(options)
|
|
43
|
-
|
|
44
|
-
创建文件系统路由引擎实例。
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { createFileSystemRouter } from '@lytjs/router-fs';
|
|
48
|
-
|
|
49
|
-
const router = createFileSystemRouter({
|
|
50
|
-
pagesDir: './src/pages',
|
|
51
|
-
basePath: '/',
|
|
52
|
-
});
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### router.addRoute(route)
|
|
56
|
-
|
|
57
|
-
添加路由。
|
|
58
|
-
|
|
59
|
-
### router.match(path)
|
|
60
|
-
|
|
61
|
-
匹配路由。
|
|
62
|
-
|
|
63
|
-
### router.getRoutes()
|
|
64
|
-
|
|
65
|
-
获取所有路由。
|
|
66
|
-
|
|
67
|
-
## 文件结构约定
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
src/
|
|
71
|
-
└── pages/
|
|
72
|
-
├── index.ts # /
|
|
73
|
-
├── about.ts # /about
|
|
74
|
-
└── user/
|
|
75
|
-
└── [id].ts # /user/:id
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## 许可证
|
|
79
|
-
|
|
80
|
-
MIT
|
|
1
|
+
# @lytjs/router-fs
|
|
2
|
+
|
|
3
|
+
LytJS 文件系统路由引擎,自动扫描文件系统生成路由配置。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @lytjs/router-fs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createFileSystemRouter } from '@lytjs/router-fs';
|
|
15
|
+
|
|
16
|
+
const router = createFileSystemRouter({
|
|
17
|
+
pagesDir: './src/pages',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 添加路由
|
|
21
|
+
router.addRoute({
|
|
22
|
+
path: '/about',
|
|
23
|
+
componentPath: './src/pages/about.ts',
|
|
24
|
+
isDynamic: false,
|
|
25
|
+
isNested: false,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// 匹配路由
|
|
29
|
+
const match = router.match('/about');
|
|
30
|
+
console.log(match); // { path: '/about', ... }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 特性
|
|
34
|
+
|
|
35
|
+
- 基于文件系统的自动路由生成
|
|
36
|
+
- 支持动态路由参数
|
|
37
|
+
- 支持嵌套路由
|
|
38
|
+
- 零外部依赖
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
### createFileSystemRouter(options)
|
|
43
|
+
|
|
44
|
+
创建文件系统路由引擎实例。
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { createFileSystemRouter } from '@lytjs/router-fs';
|
|
48
|
+
|
|
49
|
+
const router = createFileSystemRouter({
|
|
50
|
+
pagesDir: './src/pages',
|
|
51
|
+
basePath: '/',
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### router.addRoute(route)
|
|
56
|
+
|
|
57
|
+
添加路由。
|
|
58
|
+
|
|
59
|
+
### router.match(path)
|
|
60
|
+
|
|
61
|
+
匹配路由。
|
|
62
|
+
|
|
63
|
+
### router.getRoutes()
|
|
64
|
+
|
|
65
|
+
获取所有路由。
|
|
66
|
+
|
|
67
|
+
## 文件结构约定
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
src/
|
|
71
|
+
└── pages/
|
|
72
|
+
├── index.ts # /
|
|
73
|
+
├── about.ts # /about
|
|
74
|
+
└── user/
|
|
75
|
+
└── [id].ts # /user/:id
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 许可证
|
|
79
|
+
|
|
80
|
+
MIT
|