qiankun实现子应用切换到子应用传递参数
qiankun 子应用切换到子应用
基座重写跳转方法 基座 => App.tsx
import {
useState } from 'react';
import './App.css';
import {
Layout, Menu } from 'antd';
import {
Link, Routes, Route } from 'react-router-dom';
import routes from './routes';
import Home from './pages/Home';
const {
Sider, Header, Content } = Layout;
function App() {
const currentPath = window.location.pathname;
const [selectedPath, setSelectedPath] = useState(
routes.find(item => currentPath.includes(item.key))?.key || ''
);
const _wr = function (type: string) {
const orig = (window as any).history[type]
return function () {
const rv = orig.apply(this, arguments)
const e: any = new Event(type)
e.arguments = arguments
window.dispatchEvent(e)
return rv
}
}
window.history.pushState = _wr('pushState')
const bindHistory = () => {
const currentPath = window.location.pathname;
setSelectedPath(
routes.find(item => currentPath.includes(item.key))?.key || ''
)
}
window.addEventListener('pushState', bindHistory)
return (