Skip to content

Commit c113423

Browse files
YunaiVgitee-org
authored andcommitted
!172 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
Merge pull request !172 from caiti/master
2 parents 4d0e997 + 59a99af commit c113423

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/store/modules/permission.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { constantRoutes } from '@/router'
22
import { getRouters } from '@/api/menu'
33
import Layout from '@/layout/index'
44
import ParentView from '@/components/ParentView';
5+
import { toCamelCase } from "@/utils";
56

67
const permission = {
78
state: {
@@ -56,6 +57,8 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
5657
icon: route.icon,
5758
noCache: !route.keepAlive,
5859
}
60+
// 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
61+
route.name = toCamelCase(route.path, true)
5962
route.hidden = !route.visible
6063
// 处理 component 属性
6164
if (route.children) { // 父节点

src/utils/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,15 @@ export function isNumberStr(str) {
427427
return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str)
428428
}
429429

430+
// -转驼峰
431+
export function toCamelCase(str, upperCaseFirst) {
432+
str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
433+
return group1.toUpperCase();
434+
});
435+
436+
if (upperCaseFirst && str) {
437+
str = str.charAt(0).toUpperCase() + str.slice(1);
438+
}
439+
440+
return str;
441+
}

0 commit comments

Comments
 (0)