@@ -214,8 +214,8 @@ export const mounted =
214
214
on ( window , 'resize' , api . calcWidth )
215
215
216
216
if ( router ) {
217
- state . afterEach = ( ) => {
218
- api . setActiveMenu ( api . getSelectedIndex ( router . currentRoute . path ) )
217
+ state . afterEach = ( to ) => {
218
+ api . setActiveMenu ( api . getSelectedIndex ( to . path ) )
219
219
}
220
220
221
221
router . afterEach ( state . afterEach )
@@ -240,6 +240,7 @@ export const unMounted =
240
240
export const getSelectedIndex =
241
241
( state : INavMenuState ) =>
242
242
( path : string ) : number => {
243
+ if ( ! path ) return
243
244
let length = state . data . length
244
245
let index = - 1
245
246
@@ -460,6 +461,7 @@ export const clickMenu =
460
461
export const skip =
461
462
( { api, router, fields } : Pick < INavMenuRenderlessParams , 'api' | 'router' | 'fields' > ) =>
462
463
( item : menuItemType , flag = false ) : string | null => {
464
+ if ( ! router ) return
463
465
if ( item . isFullUrl ) {
464
466
const { urlField = 'url' } = fields || { }
465
467
const router = item [ urlField ] || item . route
@@ -472,7 +474,7 @@ export const skip =
472
474
: `/${ item . route || '' } ` . replace ( / ^ \/ + / , '/' ) . replace ( '#/' , '' )
473
475
474
476
if ( address ) {
475
- return router . push ( address )
477
+ return router ? .push ( address )
476
478
} else {
477
479
return ''
478
480
}
0 commit comments