2013-06-12 43 views
2

我是新來ServiceStack和角角HTML5mode和Servicestack服務時默認index.html頁面。如果這是詳細的道歉,請諒解。使用在後端

參考Html5 pushstate Urls on ServiceStack

我希望能有我的API服務從根擔任了。即http://mydomain.com/

如果用戶瀏覽的路線,我想就可以提供的是自舉我的角度應用程序的缺省HTML頁面。

在應用程序本身,如果角度調用mydomain.com/customer/{id} json應該被服務,但如果這是直接瀏覽它應該服務於默認的html頁面,並保持url但服務方法不需要被調用。因爲這將通過角度來解決,這將爲客戶服務本身調用json結果。

+0

基本上與鏈接問題相同,但我想要角度應用程序和服務API從根開始。 – Ephraim

回答

1

可能有幾種不同的方法來完成這項工作,只要你不需要支持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> 
+0

更近一步支持Angular html5mode = true,這裏:http://stackoverflow.com/q/17555259/149060 –

+0

又一步靠近這裏:http://stackoverflow.com/a/17618851/149060如果你有一個有機會試試這個,以法蓮,讓我知道它是怎麼回事。 –