[英]How to remove index.html from url on website based on angularjs
我没有找到从网址中删除index.html的方法,因为这样看起来真的很难看。
mydomain.com/index.html#/myview1
mydomain.com/index.html#/myview2
有没有办法删除该部分,就像该网址将是如此清晰的用户所在。
mydomain.com/myview1
mydomain.com/myview2
Tnx提前为您的时间。
编辑:我只是觉得它可以像以下一样工作:
mydomain.com/#/myview1
mydomain.com/#/myview2
这与index.html相比要好得多。
但是,如果有更短的解决方案让我知道。
为$location
激活html5mode
也许这种方法可以帮助:
添加$locationProvider.hashPrefix();
,在app.js配置中删除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'});
}]);
请注意,这不会删除主题标签。 您可以在以下网址找到您的新路线:... / app /#/ someroute
你必须在服务器端做一些工作来设置它。 html5mode让你成为一部分,但是一旦用户刷新,对文件的引用就会出错。 您希望链接具有持久性并且可以共享。 基本上确保任何对url.com/myapp/{etc}(或其他)的请求都被重定向到index.html,并让你的角度应用程序整理路由。
使用
<rewrite>
<rules>
<rule name="RewriteRules" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
在索引页面上
<base href="/" />
并在您的配置使用
$locationProvider.html5Mode(true);
它应该工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.