angular.js - webpack 能實現 angular-router 懶加載嗎?
問題描述
webpack打包了一個主js 然后打包成2個單獨的js 但是路由變化的時候 沒有加載這個路由的js求指教?
#core.router.jsimport LoginRouter from ’bundle?lazy!../states/login/login.route’import IndexRouter from ’bundle?lazy!../states/index/index.route’function CoreRouter($routeProvider,$locationProvider) { $routeProvider.when(’/’,IndexRouter).when(’/login’,LoginRouter).otherwise({redirectTo: ’/’});}CoreRouter.$inject = [’$routeProvider’,’$locationProvider’];export default CoreRouter;
下面是核心加載模塊
#code.module.jsimport $ from ’jquery’import ’angular-animate’import ’angular-route’;import ’angular-resource’import ’angular-cookies’import ’../../lib/toaster/toaster.min’import ’../../service/service.module’import ’../..//components/components.module’import ’../..//filter/filter.module’import ’../../service/ApiConfig’import ’../../components/loading/http-loading’;import LoginModule from ’../states/login/login.module’import IndexModule from ’../states/index/index.module’//router核心模塊最后加載import CoreRouter from ’./core.router’ //加載上面的核心路由模塊var CoreModule = angular.module(’cm.bg’,[ ’ngRoute’, ’ngCookies’, ’ngResource’, ’ngAnimate’, ’cm.filter’, ’cm.components’, ’cm.service’, ’toaster’, LoginModule.name,IndexModule.name,]) .config(CoreRouter) .run([’$rootScope’, function($rootScope){}]);export default CoreModule
問題解答
回答1:使用 ocLazyLoad 實現懶加載
相關文章:
1. python小白 關于類里面的方法獲取變量失敗的問題2. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙3. linux運維 - python遠程控制windows如何實現4. Python2中code.co_kwonlyargcount的等效寫法5. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?6. django - Python error: [Errno 99] Cannot assign requested address7. mysql數據庫做關聯一般用id還是用戶名8. [python2]local variable referenced before assignment問題9. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?10. python小白,關于函數問題
