fix[Sidebar]: link bug
This commit is contained in:
parent
30cb2df7c8
commit
1ae92fe958
|
@ -0,0 +1,39 @@
|
|||
|
||||
<template>
|
||||
<!-- eslint-disable vue/require-component-is-->
|
||||
<component v-bind="linkProps(to)">
|
||||
<slot/>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { validateURL } from '@/utils/validate'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
to: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
isExternalLink(routePath) {
|
||||
return validateURL(routePath)
|
||||
},
|
||||
linkProps(url) {
|
||||
if (this.isExternalLink(url)) {
|
||||
return {
|
||||
is: 'a',
|
||||
href: url,
|
||||
target: '_blank',
|
||||
rel: 'noopener'
|
||||
}
|
||||
}
|
||||
return {
|
||||
is: 'router-link',
|
||||
to: url
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -2,11 +2,11 @@
|
|||
<div v-if="!item.hidden&&item.children" class="menu-wrapper">
|
||||
|
||||
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
|
||||
<a :href="onlyOneChild.path" target="_blank" @click="clickLink(onlyOneChild.path,$event)">
|
||||
<app-link :to="resolvePath(onlyOneChild.path)">
|
||||
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
|
||||
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon||item.meta.icon" :title="onlyOneChild.meta.title" />
|
||||
</el-menu-item>
|
||||
</a>
|
||||
</app-link>
|
||||
</template>
|
||||
|
||||
<el-submenu v-else :index="item.name||item.path">
|
||||
|
@ -22,11 +22,11 @@
|
|||
:key="child.path"
|
||||
:base-path="resolvePath(child.path)"
|
||||
class="nest-menu" />
|
||||
<a v-else :href="child.path" :key="child.name" target="_blank" @click="clickLink(child.path,$event)">
|
||||
<app-link v-else :to="resolvePath(child.path)" :key="child.name">
|
||||
<el-menu-item :index="resolvePath(child.path)">
|
||||
<item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
|
||||
</el-menu-item>
|
||||
</a>
|
||||
</app-link>
|
||||
</template>
|
||||
</el-submenu>
|
||||
|
||||
|
@ -37,10 +37,11 @@
|
|||
import path from 'path'
|
||||
import { validateURL } from '@/utils/validate'
|
||||
import Item from './Item'
|
||||
import AppLink from './Link'
|
||||
|
||||
export default {
|
||||
name: 'SidebarItem',
|
||||
components: { Item },
|
||||
components: { Item, AppLink },
|
||||
props: {
|
||||
// route object
|
||||
item: {
|
||||
|
@ -87,17 +88,13 @@ export default {
|
|||
return false
|
||||
},
|
||||
resolvePath(routePath) {
|
||||
if (this.isExternalLink(routePath)) {
|
||||
return routePath
|
||||
}
|
||||
return path.resolve(this.basePath, routePath)
|
||||
},
|
||||
isExternalLink(routePath) {
|
||||
return validateURL(routePath)
|
||||
},
|
||||
clickLink(routePath, e) {
|
||||
if (!this.isExternalLink(routePath)) {
|
||||
e.preventDefault()
|
||||
const path = this.resolvePath(routePath)
|
||||
this.$router.push(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue