burnandbreathe
burnandbreathe

Reputation: 73

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?

Upvotes: 4

Views: 1369

Answers (1)

Khant Htet Naing
Khant Htet Naing

Reputation: 168

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

NavigateTo("mypage")

Upvotes: 5

Related Questions