从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
设置为true
:
Yes, you should configure $locationProvider
and set html5Mode
to true
:
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屋!
查看全文