[英]How to remove index.html from url on website based on angularjs
[英]Remove index.html from URL in angular JS
嗨,我在前端使用Angular JS,Java是Service層。
我正在嘗試從我的網址中刪除index.html。
現在: http://localhost:3000/Myapp/index.html#!/login
我想看起來像: http://localhost:3000/Myapp/client1#!/login
我試過了: $locationProvider.hashPrefix();
但它不起作用。
您能不能請一些建議如何使它工作。
提前致謝 !
`
這是需要在服務器上配置的東西。 您需要配置服務器以在路由Myapp/client1
上提供index.html文件
您可以為$ location激活HTML5模式:
angular.module('yourApp',[]).config(function($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
...
});
但這只會簡單地將index.html
替換為index.html
。 如果要由client1
替換,則必須在服務器上執行此操作,例如,如果使用的是apache,則在.htaccess中使用mod_rewrite
也許這種方法可以幫助:
在app.js配置中添加$ locationProvider.hashPrefix();,這將刪除URL中的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'});
}]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.