默认情况下,AngularJS将使用#符号来路由URL。例如:http://example.com/http://example.com/#/abouthttp://example.com/#/contact很容易得到一个干净的URL并从URL中删除井号。只做两件事。配置$locationProvider设置我们的相对连接源路径$location服务在Angular中,$location服务解析地址栏中的URL并对您的应用程序进行更改,反之亦然。我强烈建议阅读Angular的官方$location文档,以了解更多关于$location服务及其提供的功能的信息。$locationProvider和html5模式(html5Mode)我们将使用$locationProvider模块,并将html5Mode设置为true。我们将在您定义Angular应用程序并配置路由时执行此操作。Angular.module('scotchy',[]).config(function($routeProvider,$locationProvider){$routeProvider.when('/',{templateUrl:'partials/home.html',controller:mainController}).when('/about',{templateUrl:'partials/about.html',controller:mainController}).when('/contact',{templateUrl:'partials/contact.html',controller:mainController});//usetheHTML5HistoryAPI$locationProvider.html5Mode(true);});什么是HTML5历史API?这是使用脚本来操纵浏览器历史记录的标准方法。有了它你可以让Angular根据前提改变页面的路由和URL。有关详细信息,有一篇不错的HTML5HistoryAPI文章。为相对链接设置
