Переглянути джерело

refactor[ExternalLink]: tweak externalLink judge

Pan 6 роки тому
батько
коміт
d54bdc8fff
1 змінених файлів з 10 додано та 9 видалено
  1. 10 9
      src/views/layout/components/Sidebar/SidebarItem.vue

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

@@ -2,17 +2,11 @@
2
   <div v-if="!item.hidden&&item.children" class="menu-wrapper">
2
   <div v-if="!item.hidden&&item.children" class="menu-wrapper">
3
 
3
 
4
     <template v-if="hasOneShowingChild(item.children) && !onlyOneChild.children&&!item.alwaysShow">
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
         <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
6
         <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
8
           <item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
7
           <item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
9
         </el-menu-item>
8
         </el-menu-item>
10
       </a>
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
     </template>
10
     </template>
17
 
11
 
18
     <el-submenu v-else :index="item.name||item.path">
12
     <el-submenu v-else :index="item.name||item.path">
@@ -29,11 +23,11 @@
29
           :base-path="resolvePath(child.path)"
23
           :base-path="resolvePath(child.path)"
30
           class="nest-menu"/>
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
           <el-menu-item :index="resolvePath(child.path)">
27
           <el-menu-item :index="resolvePath(child.path)">
34
             <item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
28
             <item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
35
           </el-menu-item>
29
           </el-menu-item>
36
-        </router-link>
30
+        </a>
37
       </template>
31
       </template>
38
     </el-submenu>
32
     </el-submenu>
39
 
33
 
@@ -89,6 +83,13 @@ export default {
89
     },
83
     },
90
     isExternalLink(routePath) {
84
     isExternalLink(routePath) {
91
       return validateURL(routePath)
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
 }