I have a blazor app under the sub directory of an site on IIS. To fix blazor wasm base path problem, applied javascript code below in the head tag (suggested on elmah.io: https://blog.elmah.io/how-to-fix-blazor-wasm-base-path-problems/)
<!-- omitted for clarity -->
<head>
<base />
<script>
var path = window.location.pathname.split('/');
var base = document.getElementsByTagName('base')[0];
if (window.location.host.includes('localhost')) {
base.setAttribute('href', '/MyApp/');
} else if (path.length > 2) {
let href = '/' + path[1] + '/MyApp/';
base.setAttribute('href', href);
} else if (path[path.length - 1].length != 0) {
let fullpath = window.location.origin + window.location.pathname + '/' + window.location.search;
window.location.replace(fullpath);
}
</script>
</head>
It works pretty well and solve the blazor base path problem. But, when you enter the app url without ending with '/', the developer console fills up with 404 (not found) errors and then all of them turns out 200 (ok) ok for all css/js files. Why is it do that and can i fix it?