AngularJS:如何从URL中删除#!/(bang前缀)?
我已经完成了$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); }); 更新 更新#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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |