Browse Source

refactor[ExternalLink]: tweak externalLink judge

Pan 6 years ago
parent
commit
d54bdc8fff
1 changed files with 10 additions and 9 deletions
  1. 10 9
      src/views/layout/components/Sidebar/SidebarItem.vue

+ 10 - 9
src/views/layout/components/Sidebar/SidebarItem.vue

@@ -2,17 +2,11 @@
2 2
   <div v-if="!item.hidden&&item.children" class="menu-wrapper">
3 3
 
4 4
     <template v-if="hasOneShowingChild(item.children) && !onlyOneChild.children&&!item.alwaysShow">
5
-      <a v-if="isExternalLink(onlyOneChild.path)" :href="onlyOneChild.path" target="blank">
6
-        apple
5
+      <a :href="onlyOneChild.path" target="_blank" @click="clickLink(onlyOneChild.path,$event)">
7 6
         <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
8 7
           <item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
9 8
         </el-menu-item>
10 9
       </a>
11
-      <router-link v-else :to="resolvePath(onlyOneChild.path)">
12
-        <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
13
-          <item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
14
-        </el-menu-item>
15
-      </router-link>
16 10
     </template>
17 11
 
18 12
     <el-submenu v-else :index="item.name||item.path">
@@ -29,11 +23,11 @@
29 23
           :base-path="resolvePath(child.path)"
30 24
           class="nest-menu"/>
31 25
 
32
-        <router-link v-else :to="resolvePath(child.path)" :key="child.name">
26
+        <a v-else :href="child.path" :key="child.name" target="_blank" @click="clickLink(child.path,$event)">
33 27
           <el-menu-item :index="resolvePath(child.path)">
34 28
             <item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
35 29
           </el-menu-item>
36
-        </router-link>
30
+        </a>
37 31
       </template>
38 32
     </el-submenu>
39 33
 
@@ -89,6 +83,13 @@ export default {
89 83
     },
90 84
     isExternalLink(routePath) {
91 85
       return validateURL(routePath)
86
+    },
87
+    clickLink(routePath, e) {
88
+      if (!this.isExternalLink(routePath)) {
89
+        e.preventDefault()
90
+        const path = this.resolvePath(routePath)
91
+        this.$router.push(path)
92
+      }
92 93
     }
93 94
   }
94 95
 }