2017-10-12 75 views
0

我正在構建一個Angular 2應用。

當項目使用Visual Studio 2017年開始,我可以一個區(Home2017 /開始/ Index.cshtml)內成功地路由到相應的應用:Angular 2 + MVC路由:回退後路由失敗

Route toHome2017 = null; 
    toHome2017 = routes.MapRoute(
       name: "Default_to_Home2017", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Start", action = "Index", id = UrlParameter.Optional }, 
       namespaces: new string[] { "BIP2.Areas.Home2017.Controllers" } 
      ); 

      toHome2017.DataTokens["area"] = "Home2017"; 

角路由是:

當我導航到/ Architecture時,Angular路由工作正常。
然而,當我刷新頁面,並將其重定向到Home2017 /開始/索引使用:

toHome2017 = routes.MapRoute(
      name: "Default_to_Architecture", 
      url: "Architecture", 
      defaults: new { controller = "Start", action = "Index", id = UrlParameter.Optional }, 
      namespaces: new string[] { "BIP2.Areas.Home2017.Controllers" } 
     ); 
      toHome2017.DataTokens["area"] = "Home2017"; 

的應用程序被加載,角度路徑:「隨着StartpageComponent」被顯示的URL /建築/。

我錯過了什麼?



編輯:同樣的技術在AngularJS爲我工作

回答

0

好吧,我發現它:

運行在本地主機上的應用程序,設置基地REF:

document.write('<base href="' + document.location.href + '" />'); 

當我刷新頁面時導致基礎爲/ Architecture。
量變到質變它簡單地說:

<base href="/" /> 

解決它。