2016-11-27 134 views
0

我已经在ASP.NET MVC 4项目中实现了Angular2。 MVC路由重写了Angular 2路由。我怎样才能一起处理两个路由?Angular 2和ASP.NET MVC 4路由不能一起工作

我已经做以下修改:

_layout.cshtml:

<base href="/"/> 

app.routing.ts:

const route: Routes= [ 
{path: 'firstpage', component: firstComponent}, 
{path: 'secondpage', component: secondComponent} 
] 

我已经添加以下代码以上MVC RouteConfig.cs中的默认路由:

routes.MapRoute(
    name: "app1", 
    url: "app1/{*url}", 
    defaults: new { controller = "app1", action = "Index" } 
    ); 

我一直在使用下面的URL尝试:

http://localhost:50450/app1/firstpage

http://localhost:50450/#/app1/firstpage

仍不能正常工作,我该怎么办还是我错过了什么?

回答

1

我处理它从添加的角度路线相同的路线在我RouteConfig这样的方式:

 routes.MapRoute(
      name: "RouteName", 
      url: "routeUrl", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 

所以现在如果路由是http://localhost:3000/routeUrl .NET方面将只前进到回家的请求控制器,索引动作并将其呈现为仿佛它是这样的请求http://localhost:3000/然后角度2路由器可以接管并做它的事情。