React-Loadable跳过渲染'加载组件'

时间:2018-04-26 14:42:33

标签: javascript reactjs react-router-v4 react-loadable code-splitting-async

我正在尝试使用react-loadable在反应路由器v4中进行代码拆分。 我打算实现的是,不要用加载组件替换当前视图,而是保留当前呈现的内容。并仅更改当前加载的组件的状态。 有没有办法使用react-loadable实现这一点。或者可能是有不同的图书馆。

import Loadable from 'react-loadable';`
`import LoaderStripComponent from './LoaderStripComponent.jsx';`
`export default function Stage3Loadable(opts) {
    var loadable = Loadable(Object.assign({
        loading: LoaderStripComponent,
        timeout: 10
    }, opts));
    return loadable;
};`

`<Swtich>
 <Route exact path="/" component={Stage3Loadable({
      loader: () => import('../components/HomeCoverPage.jsx'),
      modules: ['.../components/HomeCoverPage.jsx'],
      webpack: () => [require.resolveWeak('../components/HomeCoverPage.jsx')],
    })} />
</Swtich>`

`class LoaderStripComponent extends React.Component {
    componentDidMount() {
        showLoader();
    }
    componentWillUnmount() {
        hideLoader();
    }
    componentWillReceiveProps(nextProps) {
        // console.log('>>>>>>>>>>>>', props.error);
    }
    render() {
        return null;
    }
}`
`function mapStateToProps(state) {
    return {
        device: state.device,
        geolocation: state.geoLocation,
        loader: state.routerLoading
    };
}`

`function mapDispatchToProps(dispatch) {`
    `return bindActionCreators({`

    }, dispatch);
`}`

export default connect(mapStateToProps, mapDispatchToProps)(LoaderStripComponent);

我希望此LoadableStrip呈现先前加载的组件,直到解决时间导入承诺。

0 个答案:

没有答案