AngularJS路由,从URL中删除# [英] AngularJS routing, remove # from the URL
问题描述
我正在使用AngularJS路由,并且使用了许多技巧,但是URL始终带有'#'符号.
I am using AngularJS routing and I used many tricks, but the '#' sign always comes in URL.
请参阅以下我使用的示例/代码,但并未从网址中删除#号.
Refer below Example/Code that I Used but it is not removing # sign from the URL.
angular.module('mod', []).
config(['$routeProvider', '**$locationProvider'**,
function($routeProvider, **$locationProvider**) {
$routeProvider.
when('/first', {
templateUrl: 'first.html',
controller: 'firstCtrl'
});
$locationProvider.html5Mode(true);
}]);
有人对此有解决方案吗?请分享.
Does any one have solution for this? Please share it.
推荐答案
我提出了相同的问题,并在文档上找到了解决方案.
I've came up with the same issue and found the solution on the Docs.
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
和
<head>
<base href="/">
...
</head>
如果将$ location配置为使用html5Mode(history.pushState),则您 需要使用 标记或将$ locationProvider配置为不需要基本标记 将带有requireBase:false的定义对象传递给 $ locationProvider.html5Mode():
If you configure $location to use html5Mode (history.pushState), you need to specify the base URL for the application with a tag or configure $locationProvider to not require a base tag by passing a definition object with requireBase:false to $locationProvider.html5Mode():
我们执行了错误的函数调用.试试这个,它会起作用.您也可以检查文档.
We've done the wrong function call. Try this and it will work. You can check the docs too.
这篇关于AngularJS路由,从URL中删除#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!