如何从基于 angularjs 的网站上的 url 中删除 index.html [英] How to remove index.html from url on website based on angularjs
问题描述
我没有找到从 url 中删除 index.html 的方法,因为这样看起来真的很难看.
I didn't find a way to remove index.html from the url, because like this looks really ugly.
mydomain.com/index.html#/myview1
mydomain.com/index.html#/myview2
有没有办法删除那部分,比如那个 url 会很清楚用户在哪里.
Is there a way to remove that part, like that url will be so clear where the user is.
mydomain.com/myview1
mydomain.com/myview2
提前为您安排时间.
我只是找到了它可以像这样工作的方式:
I just find way that it could work like:
mydomain.com/#/myview1
mydomain.com/#/myview2
这比 index.html 好多了.
which is pretty much better then with index.html.
但如果有更短的解决方案,请告诉我.
But still if there is a way for shorter solution let me know.
推荐答案
也许这种方法会有所帮助:
Maybe this approach could help:
在 app.js 配置中添加 $locationProvider.hashPrefix();
,它会删除 URL 中的 index.html.不要忘记添加新的依赖项.之后你的 app.js 可能看起来像这样:
Add $locationProvider.hashPrefix();
, which removes index.html in your URL, in your app.js config. Don't forget to add the new dependency. After that your app.js could look similar to this:
angular.module('myApp', [
'ngRoute'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix(); // Removes index.html in URL
$routeProvider.otherwise({redirectTo: '/someroute'});
}]);
请注意,这不会删除主题标签.您可以在以下位置找到您的新路线:.../app/#/someroute
Note that this does not remove the hashtag. You can find your new route at: .../app/#/someroute
这篇关于如何从基于 angularjs 的网站上的 url 中删除 index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!