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:
wuyiping0628 2024-08-15 23:23:13 -07:00 committed by GitHub
parent 3533664273
commit e271f5daa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -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",

View File

@ -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 ''
}