CJY0208 / react-router-cache-route

Route with cache for react-router V5 like <keep-alive /> in Vue
https://www.npmjs.com/package/react-router-cache-route
MIT License
1.16k stars 113 forks source link

动态路由不缓存 #131

Closed myhuangzhen closed 3 years ago

myhuangzhen commented 3 years ago

动态路由文件 DynamicRoutes

`import React from 'react'; import { connect } from '@cmbc/apollo'; import CacheRoute, { CacheSwitch } from 'react-router-cache-route'; import NewMfeChild from '@/components/NewMfeChild';

class DynamicRoutes extends React.Component { render () { const { childMfeApps } = this.props;

return (
  <CacheSwitch>
    {childMfeApps && childMfeApps.map((item) => {
      const { action } = item;

      return (
        <CacheRoute
          exact
          path={`/${action}`}
          key={`/${action}`}
          cacheKey={`/${action}`}
          render={props => (
            <NewMfeChild
              {...props}
              appInfo={item}
            />
          )}
        />
      );
    })}
  </CacheSwitch>
);

} }

function mapStateToProps ({ global }) { return { ...global, }; }

export default connect(mapStateToProps, null)(DynamicRoutes);`

引入上面的动态路由文件, 上面动态注册的路由缓存失效,

import React from 'react'; import { ConfigProvider } from 'antd'; import zhCN from 'antd/es/locale/zh_CN'; import { Route, Router, Switch } from '@cmbc/apollo/router'; import CacheRoute, { CacheSwitch } from 'react-router-cache-route'; import { getCacheProp } from '@/utils';

import Entry from '@/Layout/Entry'; import BasicLayout from '@/Layout/BasicLayout'; import AppSelectionLayout from '@/Layout/AppSelectionLayout';

import Home from '@/pages/home'; import DynamicRoutes from '@/components/DynamicRoutes';

// 自动获取任务 import TaskOperate from '@/pages/taskOperate';

// 超级系统管理 import ParamConfiguration from '@/pages/paramConfiguration';

function AppRouter (props) { const { history, app } = props;

return (

); }

export default AppRouter;

CJY0208 commented 3 years ago

不太理解,是说带参数的路由吗?使用 multiple 属性试试,文档中有说明