需要引入angular.js,angular-ui-router.min.js
<ul> <li><a href="#home">首页</a></li> <li><a href="#aboutUs">关于我们</a></li> <li><a href="#contactUs">联系我们</a></li> </ul> <div ui-view></div>
var app = angular.module("instruction", ['ui.router']) app.config(["$urlRouterProvider", "$stateProvider", function ($urlRouterProvider, $stateProvider) { $urlRouterProvider.otherwise("/home"); $stateProvider .state("home", { url:"/home", templateUrl: "home.html" }) .state("aboutUs", { url: "/aboutUs", templateUrl: "aboutUs.html" }) .state("contactUs", { url:"/contactUs", templateUrl: "contactUs.html" }) }])