diff --git a/src/layouts/BasicLayout1.js b/src/layouts/BasicLayout1.js index cdc600103339c7d66cb72a68a911d11907e9d6e0..6fd78c3a0a42ed4ff148a30a13ac89bb28dda0b2 100644 --- a/src/layouts/BasicLayout1.js +++ b/src/layouts/BasicLayout1.js @@ -318,21 +318,43 @@ const BasicLayout = props => { useEffect(() => { console.log(props.route.routes); }, [props.currentMenuIndex]); - window.share && window.share.event && window.share.event.on('event:updateCurrentChildrenRoutes', ({currentPath, currentRoute, selectedIndex}) => { - currentRoute && currentRoute.parent && currentRoute.parent.routes ? setChildrenRoutes(currentRoute.parent.routes): !currentRoute.parent ? setChildrenRoutes(currentRoute.routes): setChildrenRoutes([currentRoute]); - setSelectIndex(selectedIndex); - setTabActiveKey(currentPath) - }); - - window.share && window.share.event && window.share.event.on('event:favitor', ({icon, name, path}) => { - setChildrenRoutes([ - { - icon: <HomeIcon/>, - path: path, - name: name - } - ]) - }) + + useEffect(() => { + window.share && window.share.event && window.share.event.on('event:updateCurrentChildrenRoutes', ({currentPath, currentRoute, selectedIndex}) => { + currentRoute && currentRoute.parent && currentRoute.parent.routes ? setChildrenRoutes(currentRoute.parent.routes): !currentRoute.parent ? setChildrenRoutes(currentRoute.routes): setChildrenRoutes([currentRoute]); + setSelectIndex(selectedIndex); + setTabActiveKey(currentPath) + }); + + window.share && window.share.event && window.share.event.on('event:favitor', ({icon, name, path}) => { + setChildrenRoutes([ + { + icon: <HomeIcon/>, + path: path, + name: name + } + ]) + }); + + window.share && window.share.event && window.share.event.on('goHome', url => { + setChildrenRoutes([ + { + icon: <HomeIcon/>, + path: url, + name: '棣栭〉' + } + ]); + setTabActiveKey(url); + window.history.pushState(null, '', `/civbase${url}`); + }); + return () => { + window.share && window.share.event && window.share.event.removeAllListeners('event:updateCurrentChildrenRoutes'); + window.share && window.share.event && window.share.event.removeAllListeners('event:favitor'); + window.share && window.share.event && window.share.event.removeAllListeners('goHome'); + }; + }, []); + + useEffect(() => { siteAction.setGlobalConfig(props.global); if (!Cookies.get('token')) { @@ -358,21 +380,6 @@ const BasicLayout = props => { }, [props.global]); // setChildrenRoutes(currentChildrenRoute) - window.share.event.on('goHome', url => { - - setChildrenRoutes([ - { - icon: <HomeIcon/>, - path: url, - name: '棣栭〉' - } - ]); - - setTabActiveKey(url); - window.history.pushState(null, '', `/civbase${url}`); - - - }); /** * web4鍏ㄥ睆閫€鍑猴紝鍒囨崲涓夌骇鑿滃崟楂樹寒 */