Commit 22a3bf34 authored by Sendya's avatar Sendya

fix: remote path | target not work

parent da2392e8
...@@ -115,6 +115,15 @@ const asyncRouterMap = [ ...@@ -115,6 +115,15 @@ const asyncRouterMap = [
icon: 'smile' icon: 'smile'
}, },
component: () => import(/* webpackChunkName: "about" */ '../views/TestPage3') 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) ...@@ -20,7 +20,7 @@ Vue.use(VueRouter)
const routes = asyncRouterMap const routes = asyncRouterMap
const router = new VueRouter({ const router = new VueRouter({
mode: 'history', mode: 'hash',
routes 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 = { ...@@ -18,6 +18,8 @@ export const RouteMenuProps = {
i18nRender: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]).def(false), i18nRender: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]).def(false),
} }
const httpReg = /(http|https|ftp):\/\/([\w.]+\/?)\S*/
const renderMenu = (h, item, i18nRender) => { const renderMenu = (h, item, i18nRender) => {
if (item && !item.hidden) { if (item && !item.hidden) {
const bool = item.children && !item.hideChildrenInMenu const bool = item.children && !item.hideChildrenInMenu
...@@ -42,9 +44,10 @@ const renderSubMenu = (h, item, i18nRender) => { ...@@ -42,9 +44,10 @@ const renderSubMenu = (h, item, i18nRender) => {
const renderMenuItem = (h, item, i18nRender) => { const renderMenuItem = (h, item, i18nRender) => {
const meta = Object.assign({}, item.meta) const meta = Object.assign({}, item.meta)
const target = meta.target || null const target = meta.target || null
const hasRemoteUrl = httpReg.test(item.path)
const CustomTag = target && 'a' || 'router-link' const CustomTag = target && 'a' || 'router-link'
const props = { to: { name: item.name } } 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) { if (item.children && item.hideChildrenInMenu) {
// 把有子菜单的 并且 父菜单是要隐藏子菜单的 // 把有子菜单的 并且 父菜单是要隐藏子菜单的
// 都给子菜单增加一个 hidden 属性 // 都给子菜单增加一个 hidden 属性
...@@ -83,7 +86,8 @@ const RouteMenu = { ...@@ -83,7 +86,8 @@ const RouteMenu = {
return { return {
openKeys: [], openKeys: [],
selectedKeys: [], selectedKeys: [],
cachedOpenKeys: [] cachedOpenKeys: [],
cachedSelectedKeys: [],
} }
}, },
render (h) { render (h) {
...@@ -111,8 +115,10 @@ const RouteMenu = { ...@@ -111,8 +115,10 @@ const RouteMenu = {
}, },
on: { on: {
select: menu => { select: menu => {
this.selectedKeys = menu.selectedKeys
this.$emit('select', menu) this.$emit('select', menu)
if (!httpReg.test(menu.key)) {
this.selectedKeys = menu.selectedKeys
}
}, },
openChange: handleOpenChange 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