Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Blazor WASM routing not using correct base URI once deployed on a server? (NavigationManager.NavigateTo() method)

A Blazor WASM project I'm developing routes as expected when debugging on localhost. For example, after logging in, if successful, NavigateTo("/mypage") is called. This works as expected locally and takes me to "localhost:44303/mypage".

Once deployed to my test server however, it does not. The porject deploys to a folder in wwwroot so the URL format/location for the site once deployed is "test.com/MyApp/" (landing page). When it routes to another page like after logging in, it should look like "test.com/MyApp/mypage". But instead, it is routing to "test.com/mypage", completely removing the "MyApp/", which of course returns 404's everywhere.

I thought this was a simple fix of adjusting the index.html file's <base href=""> value but that did not change anything with the routing. When debugging locally, I have it at <base href="/" /> (which works). When deployed, it is <base href="/MyApp/" /> (which doesn't work). I have researched this but there doesn't seem to be a lot of encounters with this specific issue, or the recommended fix is the base href which I've already tried.

If I change the NavigateTo() methods in the project code to look like NavigateTo("MyApp/mypage"), it then works on the server, but that doesn't seem right/necessary. I shouldn't have to set those as conditional depending on whether I'm debugging or not, right?

It appears my app is dropping the base URI somewhere during the routing and I can't figure out where/why. Can anybody shed light on this?

like image 506
burnandbreathe Avatar asked Oct 19 '25 08:10

burnandbreathe


1 Answers

Remove slash "/" at the front and just use.

NavigateTo("mypage")
like image 72
Khant Htet Naing Avatar answered Oct 22 '25 06:10

Khant Htet Naing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!