简体   繁体   English

从有角JS中的URL中删除index.html

[英]Remove index.html from URL in angular JS

Hi I am using Angular JS for my Front End, Java is the Service layer. 嗨,我在前端使用Angular JS,Java是Service层。

I am trying to remove the index.html from my url. 我正在尝试从我的网址中删除index.html。

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

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

I tried : $locationProvider.hashPrefix(); 我试过了: $locationProvider.hashPrefix(); but it is not working. 但它不起作用。

Could you please some one suggest how to make it work. 您能不能请一些建议如何使它工作。

Thanks in advance ! 提前致谢 !

` `

This is something that needs to be configured on the server. 这是需要在服务器上配置的东西。 You would need to configure your server to serve the index.html file on the route Myapp/client1 您需要配置服务器以在路由Myapp/client1上提供index.html文件

you could activate the HTML5 mode for $location : 您可以为$ location激活HTML5模式:

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

But this would simply replace index.html with nothing. 但这只会简单地将index.html替换为index.html If you want to be replaced by client1 you have to do it on your server, for example with mod_rewrite in your .htaccess, if you are using apache 如果要由client1替换,则必须在服务器上执行此操作,例如,如果使用的是apache,则在.htaccess中使用mod_rewrite

Maybe this approach could help: 也许这种方法可以帮助:

Add $locationProvider.hashPrefix();, which removes index.html in your URL, in your app.js config. 在app.js配置中添加$ locationProvider.hashPrefix();,这将删除URL中的index.html。 Don't forget to add the new dependency. 不要忘记添加新的依赖项。 After that your app.js could look similar to this: 之后,您的app.js可能类似于以下内容:

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

  $routeProvider.otherwise({redirectTo: '/someroute'});
}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM