admin管理员组文章数量:1221774
I want to have an ASP.NET Server which serves an Angular SPA. The SPA should not be served at /
, but on a subpath, say /spa
. Basically that means I just have to put the angular build output results in the wwwroot
folder (the public folder for serving assets), so that e.g. the index.html
file can be found under wwwroot/spa/index.html
, so that it will be accessible at /spa(/index.html)
.
This means all assets will also be served unter this subpath, e.g. /spa/polyfills.js
. To make this work from the angular side, we need to set the html base tag accordingly to <base href="/spa/">
. This means all asset requests will be prefixed with spa
, and be therefore correct.
Now, when running Angular in development mode with ng serve
, this doesn't work. The browser will make requests to e.g. /spa/polyfills.js
, which gives me an error NS_ERROR_CORRUPTED_CONTENT
, probably because Vite can't find the file, because it is not properly configured and would only find the file at /polyfills.js
.
To fix this in Vite, the base
option could be used in a vite.config.ts
:
export default {
base: '/spa/',
}
However, Angular doesn't let one configure the Vite configuration, and I can't find a setting in Angular to adjust this behaviour. How can I fix this?
本文标签: aspnetAngular 19 with Vite and custom ltbase hrefgtStack Overflow
版权声明:本文标题:asp.net - Angular 19 with Vite and custom <base href> - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739342557a2159004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论