Commit f7688fa3 authored by 崔佳豪's avatar 崔佳豪

fix: 清除事件重复注册

parent a6e5d230
......@@ -318,6 +318,8 @@ const BasicLayout = props => {
useEffect(() => {
console.log(props.route.routes);
}, [props.currentMenuIndex]);
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);
......@@ -332,7 +334,27 @@ const BasicLayout = props => {
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全屏退出,切换三级菜单高亮
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment