forked from opentiny/tiny-vue
fix(nav-menu): [nav-menu] error occurred when modifying route redirection (#1907)
* fix(nav-menu): [nav-menu] error occurred when modifying route redirection * fix(nav-menu): [nav-menu] error occurred when modifying route redirection
This commit is contained in:
parent
3533664273
commit
e271f5daa5
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@opentiny/vue-renderless",
|
||||
"version": "3.18.0",
|
||||
"version": "3.18.1",
|
||||
"private": true,
|
||||
"description": "An enterprise-class UI component library, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.",
|
||||
"author": "OpenTiny Team",
|
||||
|
|
|
@ -214,8 +214,8 @@ export const mounted =
|
|||
on(window, 'resize', api.calcWidth)
|
||||
|
||||
if (router) {
|
||||
state.afterEach = () => {
|
||||
api.setActiveMenu(api.getSelectedIndex(router.currentRoute.path))
|
||||
state.afterEach = (to) => {
|
||||
api.setActiveMenu(api.getSelectedIndex(to.path))
|
||||
}
|
||||
|
||||
router.afterEach(state.afterEach)
|
||||
|
@ -240,6 +240,7 @@ export const unMounted =
|
|||
export const getSelectedIndex =
|
||||
(state: INavMenuState) =>
|
||||
(path: string): number => {
|
||||
if (!path) return
|
||||
let length = state.data.length
|
||||
let index = -1
|
||||
|
||||
|
@ -460,6 +461,7 @@ export const clickMenu =
|
|||
export const skip =
|
||||
({ api, router, fields }: Pick<INavMenuRenderlessParams, 'api' | 'router' | 'fields'>) =>
|
||||
(item: menuItemType, flag = false): string | null => {
|
||||
if (!router) return
|
||||
if (item.isFullUrl) {
|
||||
const { urlField = 'url' } = fields || {}
|
||||
const router = item[urlField] || item.route
|
||||
|
@ -472,7 +474,7 @@ export const skip =
|
|||
: `/${item.route || ''}`.replace(/^\/+/, '/').replace('#/', '')
|
||||
|
||||
if (address) {
|
||||
return router.push(address)
|
||||
return router?.push(address)
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue