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