我有带有路由的 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/