4
$ location /在html5和hashbang模式之间切换/链接重写
我给人的印象是Angular会重写出现在临时模板中定位标记的href属性中的URL,以便无论在html5模式还是hashbang模式下它们都可以工作。定位服务的文档似乎说HTML链接重写可以解决hashbang的问题。因此,我希望当不在HTML5模式下时,将插入哈希,而在HTML5模式下,则不会。 但是,似乎没有进行任何重写。以下示例不允许我仅更改模式。应用程序中的所有链接都需要手工重写(或在运行时从变量派生。我是否需要根据模式手动重写所有URL? 我没有看到在Angular 1.0.6、1.1.4或1.1.3中进行任何客户端url重写。似乎所有的href值都必须在#/之前添加为hashbang模式,在//之前添加为html5模式。 是否需要一些配置才能引起重写?我在读文档吗?还在做傻事吗? 这是一个小例子: <head> <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.js"></script> </head> <body> <div ng-view></div> <script> angular.module('sample', []) .config( ['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { //commenting out this line (switching to hashbang mode) breaks the app //-- unless # is added to the templates $locationProvider.html5Mode(true); $routeProvider.when('/', { template: 'this is home. go …