【发布时间】:2014-11-03 04:15:38
【问题描述】:
我有一个基于 ASP.NET 项目的 angularjs 应用程序,它使用 html5mode 并且工作得非常好,除非我想传递路由参数。
角度路由:
$locationProvider.html5Mode(true);
$routeProvider.when('/accounts', {
templateUrl: 'templates/accounts.html',
controller: 'accountsCtrl',
title: 'Accounts',
resolve: {
accounts: function (accountData) {
return accountData.getAll();
}
}
});
$routeProvider.when('/account/:accId', {
templateUrl: 'templates/editAccount.html',
controller: 'editAccountCtrl',
title: 'Account',
resolve: {
account: function ($route, accountData) {
return accountData.get($route.current.pathParams.accId);
}
}
});
web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^index\.html" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
Rout localhost:3849/accounts - 有效,但是 localhost:3849/account/1 破坏了系统,看起来它无法加载 *.js 库或任何其他资源。
控制台显示
Uncaught SyntaxError: Unexpected token <
对于每个单独的库。怎么了? 谢谢
更新 问题是如何在 index.html 中引用脚本。 原文是:
<script type="text/javascript" src="Scripts/angular.min.js"></script>
必须是:
<script type="text/javascript" src="/Scripts/angular.min.js"></script>
所以当我要求服务器访问 localhost:3849/account/1 时,它开始查看 localhost:3849/account 中的所有文件,但没有找到并返回 index.html。 路由中同样的问题,而不是
templateUrl: 'templates/editAccount.html',
必须是:
templateUrl: '/templates/editAccount.html',
【问题讨论】:
标签: javascript asp.net angularjs url-routing angular-routing