可能有幾種不同的方法來完成這項工作,只要你不需要支持html5mode網址。我曾希望我將來能夠利用this code最終支持html5mode,但在那一刻,我已經辭職了自己基於哈希的URL。
給出的網址,如:http://example.com/或http://example.com/#/customer/(編號),這裏是如何從域的根自託管servicestack項目bootstap的angularjs單頁的應用程序。
要啓用降價剃刀引擎,將它添加到您的APPHOST配置(不是絕對必要的,但我在默認剃刀引擎偏好):
Plugins.Add(new RazorFormat());
位置的文件,default.md,根你的項目,並確保它的屬性是「內容/副本時,新的」。把你想要的任何內容放在那裏。重要的是分配模板文件。 (如果您使用的是默認剃刀引擎,等效default.cshtml文件還應該工作,但我從來沒有嘗試過。)模板文件是什麼將引導您angularjs應用。這是我在我的default.md:
@template "Views\Shared\_Layout.shtml"
# This file only exists in order to trigger the load of the template file,
# which bootstraps the angular.js app
# The content of this file is not rendered by the template.
我_Layout.shtml文件看起來像這樣(忽略不相關的細節)。注意html標籤中的ng-app,以及正文中的ng-view div。另請注意,我不在文件中包含<[email protected]>
。我沒有爲這個項目使用服務器端模板。
<!DOCTYPE html>
<html lang="en" ng-app="MyApp">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="Content/css/app-specific.css"/>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<!-- Navbar goes here -->
<div class="container">
<header id="header">
<!-- Header goes here -->
</header>
<div ng-view></div>
<hr>
<footer id="footer">
<!-- Footer goes here -->
</footer>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="/Scripts/app-specific/app.js?3ba152" type="text/javascript"></script>
<script src="/Scripts/app-specific/app-services.js?3ba152" type="text/javascript"></script>
<script src="/Scripts/app-specific/app-controllers.js?3ba152" type="text/javascript"></script>
</body>
</html>
基本上與鏈接問題相同,但我想要角度應用程序和服務API從根開始。 – Ephraim