//防止用户刷新路由指向错误 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/">。
angluarjs2项目生成内容合并到asp.net mvc4项目中一起发布
原文:http://www.cnblogs.com/cnlizhipeng/p/angular2_mvc4.html