暂时关掉keepalive
This commit is contained in:
parent
2a25d8b0e0
commit
77e4b33971
|
|
@ -1,6 +1,5 @@
|
|||
import React, { useMemo } from 'react';
|
||||
import { Routes, Route, Outlet, useLocation } from 'react-router-dom';
|
||||
import KeepAlive from 'keepalive-for-react';
|
||||
import Loading from '../Loading';
|
||||
/**
|
||||
* 渲染应用路由
|
||||
|
|
@ -27,23 +26,22 @@ function RenderRouter(props) {
|
|||
};
|
||||
}
|
||||
return (<Route {...props} key={index} element={<Guard Component={Component} meta={meta} namespace={namespace} customRouter={customRouter} appName={appName} features={features}/>}>
|
||||
|
||||
{children && RenderRouter({
|
||||
routers: children,
|
||||
features,
|
||||
appName,
|
||||
})}
|
||||
routers: children,
|
||||
features,
|
||||
appName,
|
||||
})}
|
||||
</Route>);
|
||||
})}
|
||||
</>);
|
||||
}
|
||||
;
|
||||
const Guard = (props) => {
|
||||
const { Component, namespace, meta, customRouter, features } = props;
|
||||
const { Component, namespace, meta, customRouter, features, appName } = props;
|
||||
const location = useLocation();
|
||||
const { pathname } = location;
|
||||
const path = namespace ? pathname.slice(namespace.length) : pathname;
|
||||
const i18nNs = `taicang-p-${path.startsWith('/')
|
||||
const i18nNs = `${appName}-p-${path.startsWith('/')
|
||||
? path.slice(1).replaceAll(/\//g, '-')
|
||||
: path.replaceAll(/\//g, '-')}`;
|
||||
if (i18nNs) {
|
||||
|
|
@ -52,20 +50,46 @@ const Guard = (props) => {
|
|||
window.document.title = windowTitle;
|
||||
}
|
||||
}
|
||||
return Component ? (<React.Suspense fallback={<Loading />}>
|
||||
{/* <KeepAlive
|
||||
name={'path'}
|
||||
when={() => true}
|
||||
cacheKey={React.useId()}
|
||||
>
|
||||
<Component
|
||||
oakDisablePulldownRefresh={meta?.oakDisablePulldownRefresh}
|
||||
namespace={namespace || ''}
|
||||
customRouter={customRouter}
|
||||
/>
|
||||
</KeepAlive> */}
|
||||
<Component oakDisablePulldownRefresh={meta?.oakDisablePulldownRefresh} namespace={namespace || ''} customRouter={customRouter}/>
|
||||
</React.Suspense>) : (<Outlet />);
|
||||
};
|
||||
const AppRouter = (props) => {
|
||||
const { routers, appName, features } = props;
|
||||
const location = useLocation();
|
||||
/**
|
||||
* 用于区分不同页面以进行缓存
|
||||
*/
|
||||
const cacheKey = useMemo(() => {
|
||||
return location.pathname + location.search;
|
||||
}, [location]);
|
||||
return Component ? (<React.Suspense fallback={<Loading />}>
|
||||
<KeepAlive max={25} activeName={cacheKey}>
|
||||
<Component oakDisablePulldownRefresh={meta?.oakDisablePulldownRefresh} namespace={namespace || ''} customRouter={customRouter}/>
|
||||
</KeepAlive>
|
||||
</React.Suspense>) : (<Outlet />);
|
||||
};
|
||||
const AppRouter = (props) => {
|
||||
const { routers, appName, features } = props;
|
||||
// return (
|
||||
// <KeepAlive
|
||||
// max={25}
|
||||
// activeName={cacheKey}
|
||||
// >
|
||||
// <Routes>
|
||||
// {
|
||||
// RenderRouter({
|
||||
// routers,
|
||||
// features,
|
||||
// appName,
|
||||
// })
|
||||
// }
|
||||
// </Routes>
|
||||
// </KeepAlive>
|
||||
// );
|
||||
return (<Routes>
|
||||
{RenderRouter({
|
||||
routers,
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ import { FeaturesProvider } from '../features';
|
|||
import AppError from './AppError';
|
||||
import AppContainer from './AppContainer';
|
||||
import AppRouter from './AppRouter';
|
||||
import { autoFixContext } from 'react-activation';
|
||||
import 'dayjs/locale/zh-cn';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
import enUS from 'antd/locale/en_US';
|
||||
autoFixContext([require('react/jsx-runtime'), 'jsx', 'jsxs', 'jsxDEV'], [require('react/jsx-dev-runtime'), 'jsx', 'jsxs', 'jsxDEV']);
|
||||
export default function initialize(features, appName, routers, locales, error) {
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
const history = createBrowserHistory();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ function initialize(features, appName, routers, locales, error) {
|
|||
token: {
|
||||
colorPrimary: 'var(--oak-color-primary)',
|
||||
}
|
||||
}, children: (0, jsx_runtime_1.jsx)(cssinjs_1.StyleProvider, { hashPriority: "high", transformers: [cssinjs_1.legacyLogicalPropertiesTransformer], children: (0, jsx_runtime_1.jsx)(react_activation_1.AliveScope, { children: (0, jsx_runtime_1.jsx)(AppContainer_1.default, { children: (0, jsx_runtime_1.jsx)(AppRouter_1.default, { features: features, appName: appName, routers: routers }) }) }) }) }) }) }) }));
|
||||
}, children: (0, jsx_runtime_1.jsx)(cssinjs_1.StyleProvider, { hashPriority: "high", transformers: [cssinjs_1.legacyLogicalPropertiesTransformer], children: (0, jsx_runtime_1.jsx)(AppContainer_1.default, { children: (0, jsx_runtime_1.jsx)(AppRouter_1.default, { features: features, appName: appName, routers: routers }) }) }) }) }) }) }));
|
||||
}
|
||||
}
|
||||
exports.default = initialize;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ export default function initialize<ED extends BaseEntityDict>(
|
|||
hashPriority="high"
|
||||
transformers={[legacyLogicalPropertiesTransformer]}
|
||||
>
|
||||
<AliveScope>
|
||||
<AppContainer>
|
||||
<AppRouter
|
||||
features={features}
|
||||
|
|
@ -77,7 +76,6 @@ export default function initialize<ED extends BaseEntityDict>(
|
|||
routers={routers}
|
||||
/>
|
||||
</AppContainer>
|
||||
</AliveScope>
|
||||
</StyleProvider>
|
||||
</ConfigProvider>
|
||||
</FeaturesProvider>
|
||||
|
|
|
|||
Loading…
Reference in New Issue