react-router-cache-route icon indicating copy to clipboard operation
react-router-cache-route copied to clipboard

react16.3.2 + react-router 4.2.0 下使用无效

Open yezishan opened this issue 5 years ago • 4 comments

如题,在react16.3.2 + react-router 4.2.0 下使用,react-router-cache-route版本是1.8.4,页面并没有缓存,求解答

yezishan avatar Mar 21 '20 04:03 yezishan

你好,是否可以提供简单的用例?

CJY0208 avatar Mar 24 '20 00:03 CJY0208

就是按照说明文档上面来的

1、入口页面路由配置: `<LocaleProvider locale={zhCN}>

<Router history={history}> 
    <Switch>
        <Route path="/" render={getAuthRender()} />
    </Switch>
</Router>

</LocaleProvider>`

2、子页面路由配置: ` import React from 'react';

import createReactClass from 'create-react-class';

import { Redirect } from 'react-router-dom';

import CacheRoute, { CacheSwitch } from 'react-router-cache-route';

import Tab from './Tab';

const Main = createReactClass({

render() {
    const { getRouteData } = this.props;
    return (

        <div id="main" role="main">
            <Tab {...this.props} />
            <CacheSwitch>
                {
                    getRouteData().map(item => {
                        return (

                            <CacheRoute
                                exact={item.exact}
                                key={item.path}
                                path={item.path}
                                component={item.component}
                            />
                        )
                    }

                    )
                }
                <Redirect exact from="/" to="/dashboard" />
            </CacheSwitch>
        </div>
    );
}

}); ` 试过将入口页面的switch、route也替换为CacheSwitch、CacheRoute,依然不行

yezishan avatar Mar 24 '20 08:03 yezishan

是否存在嵌套路由呢?或者只是最简单的一层路由结构也会不生效?

如果有线上 demo 最好,可以尝试用 codesanbox 做一个,也可以加我微信 375564567 发 demo 压缩包过来

CJY0208 avatar Mar 24 '20 09:03 CJY0208

同样不管用。没有效果

jsm1003 avatar Mar 27 '20 06:03 jsm1003