使Angular路由在ASP.NET Core 2.0应用程序中运行 [英] Make Angular routes work inside ASP.NET Core 2.0 app

查看:106
本文介绍了使Angular路由在ASP.NET Core 2.0应用程序中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET Core 2.0应用程序,我有Angular 5应用程序。这些是单独开发的(VS2017中的第1个,VS代码中的第2个)。因此,我在VSTS中设置CD / CI,并在构建期间将Angular应用程序注入到ASP.NET Core应用程序的/ angularapp /文件夹中。

I have an ASP.NET Core 2.0 app and I have Angular 5 app. Those are developed separately (1st in VS2017, 2nd in VS Code). So I set up CD/CI in VSTS and Angular app gets injected into /angularapp/ folder of ASP.NET Core app during the build.

为了制作角度应用程序用户打开时的工作 http:// domain / angularapp 我在IIS中设置URL重写规则(所以当它命中/ angularapp时它被重写为/angularapp/index.html)。

In order to make angular app work when user opens http://domain/angularapp I set up URL rewrite rule in IIS (so when it hits /angularapp it gets rewritten to /angularapp/index.html).

但是Angular应用程序中的更深层链接呢?如果我尝试打开/ angularapp /功能,我会从ASP.NET Core 2.0中收到404错误。我可以解决这个问题吗?

But what about deeper links in Angular app? If I try to open /angularapp/feature I get the 404 error from ASP.NET Core 2.0. Can I workaround this?

推荐答案

Janne-Harju 是对的。解决方案在这里 - https://code.msdn.microsoft .COM /如何对修复最路由225ac90f 。但为了使它工作,请确保你有这个:

Janne-Harju is right. The solution is here - https://code.msdn.microsoft.com/How-to-fix-the-routing-225ac90f. But in order to make it work make sure you have this:

app.UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new List<string> { "index.html" }});

这篇关于使Angular路由在ASP.NET Core 2.0应用程序中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆