Html 在angular js中刷新页面会导致找不到url错误

Html 在angular js中刷新页面会导致找不到url错误,html,angularjs,Html,Angularjs,我创建了一个简单的AngularJS项目,其中index.html的路径是ProjectName/index.html,我的其他html文件位于ProjectName/templates/xxx.html,我的script.js路径与index.html相同。我的基本参考行是,但是当我刷新页面后,我发现页面未找到错误。 重新加载主页和学生页面时出错 Myindex.html代码 <!DOCTYPE html> <html ng-app="myModu

我创建了一个简单的
AngularJS
项目,其中
index.html
的路径是
ProjectName/index.html
,我的其他
html
文件位于
ProjectName/templates/xxx.html
,我的
script.js
路径与
index.html
相同。我的基本参考行是
,但是当我刷新页面后,我发现页面未找到错误。 重新加载主页和学生页面时出错

Myindex.html代码

       <!DOCTYPE html>
       <html ng-app="myModule">
       <head>
         <meta charset="UTF-8">
       <title>Insert title here</title>
       <base href="/routing/">
        <script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-route.min.js"></script>
<script type="text/javascript"
src="script.js"></script>
</head>
    <body>
    <table style="">
      <tr style="background-color: gray;">
        <th colspan="2" class="header"><h1>Header</h1></th>

    </tr>
    <tr>
        <td class="leftMenu" style="background-color: #cecece;"><a
            href="home">Home</a> <a href="courses">Courses</a> <a
            href="students">Students</a></td>
         <td class="mainContent" colspan="2"
             style="background-color: lightgray;"><ng-view></ng-view>                             </td> 
    </tr>
    <tr style="background-color: gray;">
        <td colspan="2" class="footer"><b>Website Footer</b></td>
</table>
</body>
</html>

Nd我的其他html文件,如home.html、students.html,可在路径Projectname/Templates/xxx.html的Templates文件夹中找到。基本href和指定的url不同:Projectname与Projectname大写在某些系统上很重要

此外,URL需要在服务器端重写,因为当您刷新页面时,会向服务器生成一个新的GET请求,这会导致404,因为服务器不知道您在Angular中定义的路由
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.html [L]
</IfModule>
重新启动发动机 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D 重写cond%{REQUEST_FILENAME}-L 重写规则。*index.html[L]
您刷新了哪个页面?你在哪一页?请在问题中添加更多细节。您能解释一下什么是projectanme capitalization@Briante吗?
指定的URL与
ProjectName/index不同。html
URL区分大小写,因此/ProjectName与/ProjectName不相同,因此在创建文件时指定/ProjectName/的基本href存储在/ProjectName/中可能会导致404。我只是将示例名称作为ProjectName。但我已经给出了正确的示例,没有任何大小写差异。答:不用担心,当我发布示例时,该示例对我不可用。我的答案将在我得到一个机会后再查看一次。我进一步查看了它-问题是,当你刷新页面时,URL已被删除已通过历史API更新,但服务器对此一无所知,因此无法提供服务。您需要在服务器端设置一些东西来重新连接URL,并为这些特定的角度路由提供index.html。这个问题似乎是重复的,而这个代码片段可以解决这个问题,真正有助于提高您的文章质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.html [L]
</IfModule>