从angular JS中的URL中删除index.html

时间:2016-05-24 09:51:10

标签: angularjs angular-ui-router

您好我在前端使用Angular JS,Java是服务层。

我正在尝试从我的网址中删除index.html。

现在:http://localhost:3000/Myapp/index.html#!/login

我想看起来像:http://localhost:3000/Myapp/client1#!/login

我尝试过:$locationProvider.hashPrefix();但它无效。

请问有人建议如何使其发挥作用。

提前致谢!

`

3 个答案:

答案 0 :(得分:-1)

这是需要在服务器上配置的内容。您需要将服务器配置为在路由Myapp/client1

上提供index.html文件

答案 1 :(得分:-1)

您可以激活$location的HTML5模式:

angular.module('yourApp',[]).config(function($locationProvider) {
    $locationProvider.html5Mode({
      enabled: true,
      requireBase: false
    });
    ...
});

但这只会简单地取代index.html。如果您想要被client1替换,则必须在服务器上执行此操作,例如在.htaccess中使用mod_rewrite,如果您使用的是apache

答案 2 :(得分:-2)

也许这种方法可以提供帮助:

在app.js配置中添加$ locationProvider.hashPrefix();,它会删除您网址中的index.html。不要忘记添加新的依赖项。之后你的app.js可能看起来像这样:

 angular.module('myApp', [
  'ngRoute'
])
.config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  $locationProvider.hashPrefix(); // Removes index.html in URL

  $routeProvider.otherwise({redirectTo: '/someroute'});
}]);
相关问题