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. javascript - react+百度地圖2. html5 - iOS的webview加載出來的H5網頁,怎么修改html標簽select的樣式字體?3. vue.js - vue+webpack+vue-router 部署到nginx服務器下,非根目錄,前后端怎樣配置文件?4. javascript - 為什么當index等于5的時候,不在當前頁面跳轉到百度?不跳轉的代碼在倒數第五行5. angular.js - 關于angular react vue 我們在什么實際的開發項目中使用?如何選擇?6. 手動啟動mysql服務出錯,1067錯誤,如何解決呢?7. index.php錯誤,求指點8. 這是什么情況???9. 請教一條mysql的sql語句寫法;10. 跟著課件一模一樣的操作使用tp6,出現了錯誤
