ionic1 路由跳转

ionic1通过路由实现按需加载的方式是在app.js中加入以下代码,即可通过对应的名称访问:

var app = angular.module("myApp",["ionic","oc.lazyLoad","ngRoute"]);

app.run(function($ionicPlatform,$state,$http, myFactory) {

  $ionicPlatform.ready(function() {
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

app.config(["$provide", "$compileProvider", "$controllerProvider", "$filterProvider",
function ($provide, $compileProvider, $controllerProvider, $filterProvider) {
    app.controller = $controllerProvider.register;
    app.directive = $compileProvider.directive;
    app.filter = $filterProvider.register;
    app.factory = $provide.factory;
    app.service = $provide.service;
    app.constant = $provide.constant;
}]);

app.config(["$httpProvider","$stateProvider","$routeProvider","$urlRouterProvider","$ocLazyLoadProvider",function($httpProvider,$stateProvider,$routeProvider,$urlRouterProvider,$ocLazyLoadProvider){
	$urlRouterProvider.otherwise("/home"); //设置默认地址

    $stateProvider
		.state("home",{   
			url: "/home",                          //访问路径
			templateUrl: "pages/home.html",        //HTML路径
			controller: "homeCtrl",                //控制器名称
			resolve: {
				deps: ['$ocLazyLoad', function($ocLazyLoad){
				  return $ocLazyLoad.load({
				  	files: [
				  		"css/home.css",            //css路径
				  		"js/homeCtrl.js"            //js路径
				  	]
				  });
				}]
			}
		})
		.state("pageone",{
			url: "/pageone",
			templateUrl: "pages/pageone.html",
			controller: "pageoneCtrl",
			resolve: {
				deps: ['$ocLazyLoad', function($ocLazyLoad){
					return $ocLazyLoad.load({
						files: [
							"css/pageone.css",
							"js/pageoneCtrl.js"
						]
					});
				}]
			}
		})
        .state("pagetwo",{
			url: "/pagetwo",
			templateUrl: "pages/pagetwo.html",
			controller: "pagetwoCtrl",
			resolve: {
				deps: ['$ocLazyLoad', function($ocLazyLoad){
					return $ocLazyLoad.load({
						files: [
							"css/pagetwo.css",
							"js/pagetwoCtrl.js"
						]
					});
				}]
			}
		});
}]);

 

你可能感兴趣的:(ionic1 路由跳转)