javascript - Angular 状态刷新页面在浏览器中不起作用

标签 javascript angularjs angular-ui-router page-refresh

我有带有路由的 Angular 应用程序:<base href="/application/">

 $stateProvider
            .state('main', {
                url: '/',
                templateUrl: 'js/templates/main.html'
            })
            .state('main.admin', {
                url: '^/admin',
                templateUrl: 'js/templates/admin-page.html',
                controller: 'AdminController'
            })...
$locationProvider.html5Mode(true);

当我使用像

这样的链接时
<li role="presentation" ui-sref-active="active">
                <a href class="custom-tab-label" ui-sref="main.admin"Admin</a>
            </li>

一切正常。链接是http://localhost:8080/application/admin

但是当我尝试刷新此页面时 - 出现 404 错误。

问题出在哪里?

最佳答案

您需要指示您的服务器端使用 Angular 路由... here is a link关于如何做到这一点...

例如在IIS中

<system.webServer>
  <rewrite>
    <rules> 
      <rule name="Main Rule" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                                 
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

关于javascript - Angular 状态刷新页面在浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31138542/

相关文章:

javascript - ag-grid api是否支持列过滤下拉

javascript - 是显示:none easing the browser rendering?

javascript - 网站是否有可能知道您是否编辑了他们的 javascript 变量?

java - 使用 Angular js 使用文件和其他输入字段进行 Spring Rest 发布请求

html - 绝对定位的内容不会显示在 angular ui-router ui-view 中

javascript - toastr 没有出现在 ui-router 子状态中

angularjs - Angular UI 路由器 - 动态 TemplateURL

javascript - AngularJS 中的一种 HTML 绑定(bind)方式

javascript - 修改正则表达式密码检查器

javascript - 在模块中捆绑 Controller 会导致 angularjs 1.5 中未定义