diff --git a/src/utils/index.js b/src/utils/index.js index f607910c4ac00dbaf6a69f1e5cba2e38e9b2e3ae..3af8b29b8ba3a9b1e473e1509e57e339cbfcadc0 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -296,3 +296,7 @@ export function deepClone(source) { export function uniqueArr(arr) { return Array.from(new Set(arr)) } + +export function isExternal(path) { + return /^(https?:|mailto:|tel:)/.test(path) +} diff --git a/src/views/layout/components/Sidebar/Link.vue b/src/views/layout/components/Sidebar/Link.vue index 07793b9a29bffd4328723c6a074cd4e10267601d..5d366f246c38d6a13dd50476a2ce88124cc13101 100644 --- a/src/views/layout/components/Sidebar/Link.vue +++ b/src/views/layout/components/Sidebar/Link.vue @@ -7,7 +7,7 @@ </template> <script> -import { validateURL } from '@/utils/validate' +import { isExternal } from '@/utils' export default { props: { @@ -18,7 +18,7 @@ export default { }, methods: { isExternalLink(routePath) { - return validateURL(routePath) + return isExternal(routePath) }, linkProps(url) { if (this.isExternalLink(url)) { diff --git a/src/views/layout/components/Sidebar/SidebarItem.vue b/src/views/layout/components/Sidebar/SidebarItem.vue index 9398af871f1dd0bcb95f6ade778acabc4c5b8db0..8a9b439687b3a65037d6f01a2d5c39883f5a0808 100644 --- a/src/views/layout/components/Sidebar/SidebarItem.vue +++ b/src/views/layout/components/Sidebar/SidebarItem.vue @@ -37,7 +37,7 @@ <script> import path from 'path' import { generateTitle } from '@/utils/i18n' -import { validateURL } from '@/utils/validate' +import { isExternal } from '@/utils' import Item from './Item' import AppLink from './Link' import FixiOSBug from './FixiOSBug' @@ -98,7 +98,7 @@ export default { return path.resolve(this.basePath, routePath) }, isExternalLink(routePath) { - return validateURL(routePath) + return isExternal(routePath) }, generateTitle }