在angular中他的自帶路由是 ng-route.可是它的缺點很大,其中單個視圖是最致命的一點。html
全部咱們可使用第三方路由 ui-route。它主要針對多視圖的嵌套。app
ng-routeide
jsui
var app=angular.module('App',['ngRoute']); app.config(function($routeProvider){ $routeProvider .when('/', { templateUrl: 'views/login.html' }) .when('/1', { templateUrl: 'views/regist.html' }) .otherwise({ redirectTo: '/' }); });
htmlurl
<script src='angular-route.js'></script>//引入 <div ng-view=''></div>//html 插入
ui.routespa
jscode
var app=angular.module('birthdayApp',['ui.router']); app.config(function($stateProvider,$urlRouterProvider){ $urlRouterProvider.otherwise('/'); $stateProvider .state('1', { url: "/1", views: { 'view': { templateUrl: 'views/login.html', controller: 'loginCtr' } } }); $stateProvider .state('2', { url: "/2", views: { 'view': { templateUrl: 'views/regist.html', controller: 'registCtr' } } }); });
htmlrouter
<script src='angular-ui-router.js'></script> <div ui-view="view"></div>