@ruan-cat/utils 1.0.4 → 1.1.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.
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Options } from "unplugin-vue-router";
|
|
2
|
+
|
|
3
|
+
type GetRouteName = NonNullable<Options["getRouteName"]>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 自主生成路由名称
|
|
7
|
+
* @description
|
|
8
|
+
* 对插件自动生成的路由名称,很不满意,不好看,容易引起阅读歧义。
|
|
9
|
+
*
|
|
10
|
+
* 故自定义。
|
|
11
|
+
*
|
|
12
|
+
* unplugin-vue-router 插件的 getRouteName 配置项
|
|
13
|
+
*/
|
|
14
|
+
export const getRouteName: GetRouteName = function _getRouteName(node): ReturnType<GetRouteName> {
|
|
15
|
+
// 如果是根节点 那么没有对应的文件夹名称 返回空字符串
|
|
16
|
+
if (!node.parent) {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 上一次递归产生的字符串 */
|
|
21
|
+
const last = _getRouteName(node.parent);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 路由名称链接符
|
|
25
|
+
* @description
|
|
26
|
+
* 如果上一次递归产生的字符串为空,则不需要链接符
|
|
27
|
+
*/
|
|
28
|
+
const connector = last === "" ? "" : "-";
|
|
29
|
+
|
|
30
|
+
/** 当前节点的路由名称 */
|
|
31
|
+
const current = node.value.rawSegment === "index" ? "" : `${connector}${node.value.rawSegment}`;
|
|
32
|
+
|
|
33
|
+
// 返回上一次递归产生的字符串和当前节点的路由名称的拼接
|
|
34
|
+
// 从后面逐步拼接
|
|
35
|
+
return last + current;
|
|
36
|
+
};
|