Open zhanglp520 opened 1 year ago
//main.tsx或者index.tsx中 const handleMicroData = () => { const navigate = useNavigate();//报错,原因是需要在组件中使用 const location = useLocation();//报错 if (window.eventCenterForAppSource) { const dt = window.eventCenterForAppSource.getData(); console.log("微应用【app-source】 getData:", dt); if (dt.path && typeof dt.path === "string") { console.log("子应用得到的路由-初始", dt.path, location.pathname); dt.path = dt.path.replace(/^#/, ""); if (dt.path && dt.path !== location.pathname) { debugger; navigate(dt.path as string); } } window.eventCenterForAppSource.addDataListener( (data: Record<string, unknown>) => { console.log("微应用【app-source】addDataListener:", data); if (data.path && typeof data.path === "string") { console.log("子应用得到的路由", data.path, location.pathname); data.path = data.path.replace(/^#/, ""); if (data.path && data.path !== location.pathname) { debugger; navigate(dt.path as string); } } } ); setTimeout(() => { window.eventCenterForAppSource.dispatch({ myname: "appSource" }); }, 3000); } };
//main.tsx或者index.tsx中 const handleMicroData = () => { const navigate = useNavigate();//报错,原因是需要在组件中使用 const location = useLocation();//报错 if (window.eventCenterForAppSource) { const dt = window.eventCenterForAppSource.getData(); console.log("微应用【app-source】 getData:", dt); if (dt.path && typeof dt.path === "string") { console.log("子应用得到的路由-初始", dt.path, location.pathname); dt.path = dt.path.replace(/^#/, ""); if (dt.path && dt.path !== location.pathname) { debugger; navigate(dt.path as string); } } window.eventCenterForAppSource.addDataListener( (data: Record<string, unknown>) => { console.log("微应用【app-source】addDataListener:", data); if (data.path && typeof data.path === "string") { console.log("子应用得到的路由", data.path, location.pathname); data.path = data.path.replace(/^#/, ""); if (data.path && data.path !== location.pathname) { debugger; navigate(dt.path as string); } } } ); setTimeout(() => { window.eventCenterForAppSource.dispatch({ myname: "appSource" }); }, 3000); } };