Blazor WASM Hosted uses wrong basepath on page reload
Hello! I have a web app that mostly works as it should, except on a Page Refresh or direct accessing of a specific page/directory.
That is, when accessing this web app with
domain.com
, the page loads as it is supposed to and everything works.
However, when loaded directly as domain.com/directory
, Blazor cannot find css/app.css
nor _framework/blazor.webassembly.js
because it searches for them at ~/directory/css/app
.
This web app is hosted as a Docker image in Google Kubernetes Engine on Google Cloud Platform.
Note that it works automatically when running locally with dotnet watch run
, but it does not work when hosted on GCP.
My web app is set up for prerendering, and the server contains a _Host.cshtml
and _Layout.cshtml
files rather than wwwroot/index.html
on the client.
I have <base href="/" />
in _Layout.cshtml
, and have also added <StaticWebAssetBasePath>/</StaticWebAssetBasePath>
to the Client csproj, but neither fixed the issue.
Any idea why it loads the wrong base path when refreshed or directly accessed?1 Reply
Picture 1 shows how it should be, and Picture 2 shows how it attempts to find files when the page is refreshed from
domain.com/product
Found the issue. This was caused by an old leftover code snippet, that I had missed.