Commit 22a3bf34 authored by Sendya's avatar Sendya

fix: remote path | target not work

parent da2392e8
......@@ -115,6 +115,15 @@ const asyncRouterMap = [
icon: 'smile'
},
component: () => import(/* webpackChunkName: "about" */ '../views/TestPage3')
},
{
path: 'http://www.baidu.com/',
name: 'remote-baidu',
meta: {
title: '百度',
icon: 'smile',
target: '_blank'
}
}
]
}
......
......@@ -20,7 +20,7 @@ Vue.use(VueRouter)
const routes = asyncRouterMap
const router = new VueRouter({
mode: 'history',
mode: 'hash',
routes
})
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,6 +18,8 @@ export const RouteMenuProps = {
i18nRender: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]).def(false),
}
const httpReg = /(http|https|ftp):\/\/([\w.]+\/?)\S*/
const renderMenu = (h, item, i18nRender) => {
if (item && !item.hidden) {
const bool = item.children && !item.hideChildrenInMenu
......@@ -42,9 +44,10 @@ const renderSubMenu = (h, item, i18nRender) => {
const renderMenuItem = (h, item, i18nRender) => {
const meta = Object.assign({}, item.meta)
const target = meta.target || null
const hasRemoteUrl = httpReg.test(item.path)
const CustomTag = target && 'a' || 'router-link'
const props = { to: { name: item.name } }
const attrs = { href: item.path, target: target }
const attrs = (hasRemoteUrl || target) ? { href: item.path, target: target } : {}
if (item.children && item.hideChildrenInMenu) {
// 把有子菜单的 并且 父菜单是要隐藏子菜单的
// 都给子菜单增加一个 hidden 属性
......@@ -83,7 +86,8 @@ const RouteMenu = {
return {
openKeys: [],
selectedKeys: [],
cachedOpenKeys: []
cachedOpenKeys: [],
cachedSelectedKeys: [],
}
},
render (h) {
......@@ -111,8 +115,10 @@ const RouteMenu = {
},
on: {
select: menu => {
this.selectedKeys = menu.selectedKeys
this.$emit('select', menu)
if (!httpReg.test(menu.key)) {
this.selectedKeys = menu.selectedKeys
}
},
openChange: handleOpenChange
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment