Browse Source

fix[ExternalLink]: fixed bug when url include chinese

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

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

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