带.NET内核的Angular2路由
我有一个ASP.NET核心应用程序,它使用angular2路由。按预期运行本地路由解析。当我发布到服务器(运行IIS 7)时,路由似乎解析到服务器根目录,而不是它们部署到的网站,但是,它们仍然呈现页面。在下面的示例中,“页面url”是我导航到的页面,但“结果url”是显示在浏览器地址栏中的内容带.NET内核的Angular2路由,angular,asp.net-core,Angular,Asp.net Core,我有一个ASP.NET核心应用程序,它使用angular2路由。按预期运行本地路由解析。当我发布到服务器(运行IIS 7)时,路由似乎解析到服务器根目录,而不是它们部署到的网站,但是,它们仍然呈现页面。在下面的示例中,“页面url”是我导航到的页面,但“结果url”是显示在浏览器地址栏中的内容 page url --> http://myserver/myapp/home result url --> http://myserver/home 关于为什么会发生这种情况有什么想法吗
page url --> http://myserver/myapp/home
result url --> http://myserver/home
关于为什么会发生这种情况有什么想法吗?这是IIS设置、角度路由问题还是.NET核心配置问题?
以下是我在angular2中配置路线的方式
const routes: ClientRouterConfig = [
{ displayName: 'Dashboard', icon: 'fa fa-tachometer', path: '', redirectTo: 'home', pathMatch: 'full' },
{ showInNavigationMenu: true, displayName: 'Dashboard', icon: 'fa fa-tachometer', path: 'home', component: HomeComponent },
{ showInNavigationMenu: true, displayName: 'New Work Order', icon: 'fa fa-plus', path: 'workorder', component: WorkorderComponent },
{ showInNavigationMenu: false, displayName: 'Work Order', icon: 'fa fa-wrench', path: 'workorder/:id', component: WorkorderComponent },
{ showInNavigationMenu: false, displayName: 'New Task', icon: 'fa fa-user', path: 'task/create/:woid', component: TaskComponent },
{ showInNavigationMenu: false, displayName: 'Task', icon: 'fa fa-user', path: 'task/:id', component: TaskComponent },
{ displayName: 'Dashboard', icon: 'fa fa-tachometer', path: '**', redirectTo: 'home' } //this must be last
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
getRoutes() {
return routes;
}
}
我发现它:
您必须在应用程序的index.html中添加
元素,pushState路由才能正常工作。当引用CSS文件、脚本和图像时,浏览器使用
值作为相对URL的前缀
所以在你的情况下,我想是:
<base href="/myapp/" >
你有没有尝试过添加吊杆?就是这样!非常感谢!如果你想把它作为答案贴出来,我会把它标对的