将Angular 4集成到ASP.NET Core MVC应用程序中 - 如何混合路由

问题描述 投票:1回答:1

我正在尝试将我的Angular 4应用程序集成到asp.net mvc核心项目中。我想在我的Core MVC项目中使用此Url - mydomain.com/ngx提供Angular应用程序。

这是我现在的方式(它不起作用):

我使用angular-cli构建Angular应用程序并使用ng build ... --base-href /ngx(注意斜杠)。然后我从dist文件夹(通过CLI放置构建)复制所有内容,并将其复制到wwwroot/ngx文件夹中,进入我的Core MVC项目。但是当我打开localhost/ngx/index.html时,我得到了main.bundle.js和其他js文件的404错误。我检查了请求,由于某种原因,它试图把它作为localhost://main.bundle.js - 为什么从根?

现在,如果我用--base-href ngx(没有斜线)构建它并打开网站,它会被重定向到/ ngx / ngx(使ngx加倍)。所以... wtf? :)

核心MVC路由没有什么特别的,我没有触及那部分。

那么我怎样才能使它成为localhost/ngx ASP.NET核心MVC项目?

angular asp.net-core asp.net-core-mvc
1个回答
4
投票

这里工作正常

ng build --base-href /ngx/ --output-path dist/ngx, 

从dist目录运行http-server,然后转到http://localhost:8080/ngx/index.html

© www.soinside.com 2019 - 2024. All rights reserved.