react-loadable路由懶加載


load.js

import Loadable from 'react-loadable';
import './styles/load.styl'
// 按需加載組件
export default function withLoadable (comp) {
    return Loadable({
        loader:comp,
        loading:(props)=>{
            let msg
            if (props.error) {
                return <p>加載錯誤,請刷新</p>
            } else if (props.timedOut) {
                return <p>加載超時</p>
            } else if (props.pastDelay) {
                return(
                  <div className='loading-mask'>
                    <div className='container'>
                      <img className='loading-img' src={require('../images/loading.png')} />
                      <p>加載中...</p>
                    </div>
                  </div>
                )
            } else {
                return null;
            }
        },
        timeout:10000
    })
}

 

index.js

import Loadable from './assets/load';

const Indexpages = Loadable(()=>import('./pages/Indexpages/index'))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM