Bladeren bron

fix[ExternalLink]: fixed bug when url include chinese

Pan 6 jaren geleden
bovenliggende
commit
54c2b2848e

+ 4 - 0
src/utils/index.js

@@ -68,3 +68,7 @@ export function formatTime(time, option) {
68 68
     )
69 69
   }
70 70
 }
71
+
72
+export function isExternal(path) {
73
+  return /^(https?:|mailto:|tel:)/.test(path)
74
+}

+ 2 - 2
src/views/layout/components/Sidebar/Link.vue

@@ -7,7 +7,7 @@
7 7
 </template>
8 8
 
9 9
 <script>
10
-import { validateURL } from '@/utils/validate'
10
+import { isExternal } from '@/utils'
11 11
 
12 12
 export default {
13 13
   props: {
@@ -18,7 +18,7 @@ export default {
18 18
   },
19 19
   methods: {
20 20
     isExternalLink(routePath) {
21
-      return validateURL(routePath)
21
+      return isExternal(routePath)
22 22
     },
23 23
     linkProps(url) {
24 24
       if (this.isExternalLink(url)) {

+ 2 - 2
src/views/layout/components/Sidebar/SidebarItem.vue

@@ -35,7 +35,7 @@
35 35
 
36 36
 <script>
37 37
 import path from 'path'
38
-import { validateURL } from '@/utils/validate'
38
+import { isExternal } from '@/utils'
39 39
 import Item from './Item'
40 40
 import AppLink from './Link'
41 41
 
@@ -94,7 +94,7 @@ export default {
94 94
       return path.resolve(this.basePath, routePath)
95 95
     },
96 96
     isExternalLink(routePath) {
97
-      return validateURL(routePath)
97
+      return isExternal(routePath)
98 98
     }
99 99
   }
100 100
 }