Bladeren bron

fix #697 when the menu path is url, the parent path is not spliced

jim 8 jaren geleden
bovenliggende
commit
4893296e99
2 gewijzigde bestanden met toevoegingen van 15 en 1 verwijderingen
  1. 7 1
      src/common/menu.js
  2. 8 0
      src/utils/utils.js

+ 7 - 1
src/common/menu.js

@@ -1,3 +1,5 @@
+import { isUrl } from '../utils/utils';
+
 const menuData = [{
   name: 'dashboard',
   icon: 'dashboard',
@@ -120,9 +122,13 @@ const menuData = [{
 
 function formatter(data, parentPath = '', parentAuthority) {
   return data.map((item) => {
+    let { path } = item;
+    if (!isUrl(path)) {
+      path = parentPath + item.path;
+    }
     const result = {
       ...item,
-      path: `${parentPath}${item.path}`,
+      path,
       authority: item.authority || parentAuthority,
     };
     if (item.children) {

+ 8 - 0
src/utils/utils.js

@@ -132,3 +132,11 @@ export function getRoutes(path, routerData) {
   });
   return renderRoutes;
 }
+
+
+/* eslint no-useless-escape:0 */
+const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g;
+
+export function isUrl(path) {
+  return reg.test(path);
+}