AngularJS路由,没有散列’#’
发布时间:2020-12-17 09:30:57 所属栏目:安全 来源:网络整理
导读:我正在学习AngularJS,有一件事真的让我很恼火。 我使用$ routeProvider声明我的应用程序的路由规则: $routeProvider.when('/test',{ controller: TestCtrl,templateUrl: 'views/test.html'}).otherwise({ redirectTo: '/test' }); 但是当我在浏览器中导航
我正在学习AngularJS,有一件事真的让我很恼火。
我使用$ routeProvider声明我的应用程序的路由规则: $routeProvider.when('/test',{ controller: TestCtrl,templateUrl: 'views/test.html' }) .otherwise({ redirectTo: '/test' }); 但是当我在浏览器中导航到我的应用程序时,我看到app /#/ test而不是app / test。 所以我的问题是为什么AngularJS添加这个哈希#到urls?有没有可能避免呢?
事实上,你需要#(hashtag)非HTML5浏览器。
否则,它们将仅仅通过所提到的href对服务器进行HTTP调用。 您可以使用$ locationProvider.html5Mode(true)来告诉angular如何使用HTML5策略(如果有的话)。 这里支持HTML5的浏览器列表:http://caniuse.com/#feat=history (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |