Skip to content

Commit b09d2a7

Browse files
committed
fix(nav-menu): [nav-menu] error occurred when modifying route redirection
1 parent fa3a4ab commit b09d2a7

File tree

1 file changed

+5
-3
lines changed
  • packages/renderless/src/nav-menu

1 file changed

+5
-3
lines changed

packages/renderless/src/nav-menu/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ export const mounted =
214214
on(window, 'resize', api.calcWidth)
215215

216216
if (router) {
217-
state.afterEach = () => {
218-
api.setActiveMenu(api.getSelectedIndex(router.currentRoute.path))
217+
state.afterEach = (to) => {
218+
api.setActiveMenu(api.getSelectedIndex(to.path))
219219
}
220220

221221
router.afterEach(state.afterEach)
@@ -240,6 +240,7 @@ export const unMounted =
240240
export const getSelectedIndex =
241241
(state: INavMenuState) =>
242242
(path: string): number => {
243+
if (!path) return
243244
let length = state.data.length
244245
let index = -1
245246

@@ -460,6 +461,7 @@ export const clickMenu =
460461
export const skip =
461462
({ api, router, fields }: Pick<INavMenuRenderlessParams, 'api' | 'router' | 'fields'>) =>
462463
(item: menuItemType, flag = false): string | null => {
464+
if (!router) return
463465
if (item.isFullUrl) {
464466
const { urlField = 'url' } = fields || {}
465467
const router = item[urlField] || item.route
@@ -472,7 +474,7 @@ export const skip =
472474
: `/${item.route || ''}`.replace(/^\/+/, '/').replace('#/', '')
473475

474476
if (address) {
475-
return router.push(address)
477+
return router?.push(address)
476478
} else {
477479
return ''
478480
}

0 commit comments

Comments
 (0)