加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS:如何从URL中删除#!/(bang前缀)?

发布时间:2020-12-17 08:53:47 所属栏目:安全 来源:网络整理
导读:我已经完成了$locationProvider. html5Mode(true);但它不起作用.每当我访问http://example.com时,都会访问http://example.com/#!/.代码在这里给出: var myApp = angular.module('myApp',['ui.router','ui.bootstrap']);myApp.config(['$qProvider',function
我已经完成了$locationProvider. html5Mode(true);但它不起作用.每当我访问http://example.com时,都会访问http://example.com/#!/.代码在这里给出:
var myApp = angular.module('myApp',['ui.router','ui.bootstrap']);

myApp.config(['$qProvider',function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

myApp.config(function($stateProvider,$urlRouterProvider,$locationProvider) {
    // For any unmatched url,redirect to EXTRANET home page
    $urlRouterProvider.otherwise('/');
    // Now set up the states
    $stateProvider
    .state('listrole',{
    url: "/list-role",views: {
      'main-content': {
        templateUrl: rootUrl+ 'views/main.html',controller: 'rolesCtrl'
      }
    }
    })
    $locationProvider.hashPrefix('');
    $locationProvider.html5Mode(true);
});

更新
我添加了$locationProvider.hashPrefix(”);同样但没有区别.另外,让我告诉你,我在地址栏中输入地址并点击进入.我做对了吗?浏览器如何发现它不需要从服务器刷新?

更新#2

理想情况下,我希望将URL设置为http://example.com,将http://example.com/#!/list-role设置为http://example.com/list-role.现在http://example.com/list-role给出了404

更新#3

我正在使用nginx代理,如果这有帮助.

更新#4

删除缓存.现在我可以看到http://example.com而不是http://example.com/#!但仍然http://example.com/list-role给出了404

如果要删除此前缀,请将此代码添加到配置中:
appModule.config(['$locationProvider',function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

Source here获取更多信息.

更新

如果你想删除整个前缀(#而不仅仅是!),你可以尝试this solution:

1)激活HTML5模式并删除前缀!在你的模块配置中

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');

2)然后将基数设置为< head>中的/在index.html上

<head>
    ...
    <base href="/">
</head>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读