2017-10-12 93 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="/" /> 

解决它。