【发布时间】:2018-03-24 04:39:40
【问题描述】:
我正在构建一个 Angular 2 应用程序。
使用 Visual Studio 2017 启动项目时,我可以成功路由到区域内的应用程序 (Home2017/Start/Index.cshtml):
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";
角度路由是:
RouterModule.forRoot([
{
path: 'Architecture',
component: ArchitectureComponent,
pathMatch: 'full'
},
{
path: '',
component: StartpageComponent,
pathMatch: 'full'
}
])
]
当我导航到 /Architecture 时,Angular 路由正在工作。
但是,当我刷新页面并使用以下命令将其重定向到 Home2017/Start/Index 时:
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 的 Angular 路径:'' 与 Url /Architecture/ 一起显示。
我错过了什么?
编辑:同样的技术在 AngularJS 中对我有用
【问题讨论】:
标签: javascript asp.net-mvc angular asp.net-mvc-4 typescript