From 4893296e9903cd2b89883b9a36743df31647e979 Mon Sep 17 00:00:00 2001 From: jim Date: Tue, 16 Jan 2018 09:47:08 +0800 Subject: [PATCH] fix #697 when the menu path is url, the parent path is not spliced --- src/common/menu.js | 8 +++++++- src/utils/utils.js | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common/menu.js b/src/common/menu.js index 7093151c..75f47dcf 100644 --- a/src/common/menu.js +++ b/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) { diff --git a/src/utils/utils.js b/src/utils/utils.js index e80cce5b..46a0a0f2 100644 --- a/src/utils/utils.js +++ b/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); +} -- GitLab