|
|
@ -50,21 +50,33 @@ const getBusKey = (name, path, data) => { |
|
|
// 添加扩展方法
|
|
|
// 添加扩展方法
|
|
|
const $globalExpandRouter = (router, routes) => { |
|
|
const $globalExpandRouter = (router, routes) => { |
|
|
// 扩展push方法
|
|
|
// 扩展push方法
|
|
|
const routerPush = router.push; |
|
|
const routerPush = router.push.bind(router); |
|
|
router.push = (location) => { |
|
|
router.push = (location) => { |
|
|
const { name = "", path = "" } = location; |
|
|
const name = typeof location === "object" && location ? location.name || "" : ""; |
|
|
|
|
|
const path = |
|
|
|
|
|
typeof location === "object" && location |
|
|
|
|
|
? location.path || "" |
|
|
|
|
|
: typeof location === "string" |
|
|
|
|
|
? location |
|
|
|
|
|
: ""; |
|
|
const subMsgKey = getBusKey(name, path, routes); |
|
|
const subMsgKey = getBusKey(name, path, routes); |
|
|
return routerPush.call(this, location).then(() => { |
|
|
return routerPush(location).then(() => { |
|
|
subMsgKey && $globalEventBus.emit(subMsgKey); |
|
|
subMsgKey && $globalEventBus.emit(subMsgKey); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 扩展replace方法
|
|
|
// 扩展replace方法
|
|
|
const routerReplace = router.replace; |
|
|
const routerReplace = router.replace.bind(router); |
|
|
router.replace = (location) => { |
|
|
router.replace = (location) => { |
|
|
const { name = "", path = "" } = location; |
|
|
const name = typeof location === "object" && location ? location.name || "" : ""; |
|
|
|
|
|
const path = |
|
|
|
|
|
typeof location === "object" && location |
|
|
|
|
|
? location.path || "" |
|
|
|
|
|
: typeof location === "string" |
|
|
|
|
|
? location |
|
|
|
|
|
: ""; |
|
|
const subMsgKey = getBusKey(name, path, routes); |
|
|
const subMsgKey = getBusKey(name, path, routes); |
|
|
return routerReplace.call(this, location).then(() => { |
|
|
return routerReplace(location).then(() => { |
|
|
subMsgKey && $globalEventBus.emit(subMsgKey); |
|
|
subMsgKey && $globalEventBus.emit(subMsgKey); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|