//防止用戶刷新路由指向錯誤 routes.MapRoute( name: "ngdefault", url: "content/dist/{*.}", defaults: new { controller = "Home", action = "Index" } ); //原NG2開發框架中的調用內容 routes.MapRoute( name: "MyRoute", url: "api/{controller}/{action}" ); //正常的頁面請求 routes.MapRoute( name: "Default", url: "{controller}/{action}/{*pathInfo}", defaults: new { controller = "Home", action = "Index"} );
頁面設置(以下為我的Home控制器Index對應的頁面內容)
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <base href="/content/dist/"> </head> <body> <app-root></app-root>
@* 以下內容要根據你的NG2項目的生成內容來設置,具體請參照你的NG2項目引導頁面的內容。 *@ <script type="text/javascript" src="~/content/dist/inline.js"></script> <script type="text/javascript" src="~/content/dist/styles.41c78f28e60ca8b5fd69.bundle.js"></script> <script type="text/javascript" src="~/content/dist/scripts.bc1943ee0f025606a729.bundle.js"></script> <script type="text/javascript" src="~/content/dist/main.2ad5580a0f71e9dcee3e.bundle.js"></script> </body> </html>
NG2項目放置位置
發布內容放到content目錄下,所以index頁面需要在head中設置<base href="/content/dist/">。