I have an aspnet core single page app with client-side routing. We have it set to return the index.html page for any unknown path, so that the SPA can startup and handle rendering the page correctly.
Our static assets (css,js,png) also return the index.html page, which causes us a lot of trouble with our caching. I want it to return a 404 for all static files.
Is it possible to have named files like (css, js, png) all return a 404 if not found, but all other routes default to return index.html?
Here is our code that returns static files and serves the SPA:
app.UseSpaStaticFiles();
app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp/src"; });
I expect that requests to named files return a 404, and paths return the index.html
- GET /fileDoesntExist.js -> 404
- GET /fileDoesntExist.css -> 404
- GET /fileDoesExist.css -> 200 fileDoesExist.css
- GET /aPage -> 200 index.html
- GET /someOtherPage -> 200 index.html
Steve is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.