javaScript

angular 1x -- Ui-Router Dome

2017-07-20  本文已影响4人  反者道之动001

ui-router 笔录

HTML
<div ng-app="app">
  <a ui-sref="home" ui-sref-active="active">home</a>
  <a ui-sref="about" ui-sref-active="active">About</a>
  <ui-view></ui-view>
</div>

JS
var myApp = angular.module('app', ['ui.router'])
myApp.config(function($stateProvider) {
  var homeState = {
    name: 'home',
    url: '/home',
    template: home
  }

  var aboutState = {
    name: 'about',
    url: '/about',
    template: about
  }
  
  var stateArr = [
    homeState,aboutState
  ]
  
  stateArr.forEach(function(e){
    $stateProvider.state(e)
  })
  
})
重定向
myApp.config(['$stateProvider', '$urlRouterProvider',
    function($stateProvider, $urlRouterProvider) {
        $urlRouterProvider
            // 路由重定向
            .when('/', '/home')
            .otherwise('/');
    }
])
上一篇下一篇

猜你喜欢

热点阅读