从 AngularJS 网址中删除片段标识符(# 符号) [英] Removing the fragment identifier from AngularJS urls (# symbol)
本文介绍了从 AngularJS 网址中删除片段标识符(# 符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从 angular.js URL 中删除 # 符号?
Is it possible to remove the # symbol from angular.js URLs?
当我更改视图并将使用参数更新 URL 时,我仍然希望能够使用浏览器的后退按钮等,但我不想要 # 符号.
I still want to be able to use the browser's back button, etc, when I change the view and will update the URL with params, but I don't want the # symbol.
教程 routeProvider 声明如下:
The tutorial routeProvider is declared as follows:
angular.module('phonecat', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}).
when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
otherwise({redirectTo: '/phones'});
}]);
我可以在没有 # 的情况下编辑它以具有相同的功能吗?
Can I edit this to have the same functionality without the #?
推荐答案
是的,你应该配置 $locationProvider
并将 html5Mode
设置为真
:
angular.module('phonecat', []).
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/phones', {templateUrl: 'partials/phone-list.html', controller: PhoneListCtrl}).
when('/phones/:phoneId', {templateUrl: 'partials/phone-detail.html', controller: PhoneDetailCtrl}).
otherwise({redirectTo: '/phones'});
$locationProvider.html5Mode(true);
}]);
这篇关于从 AngularJS 网址中删除片段标识符(# 符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文