I suggest to use the extension method presented here:
https://chrissainty.com/working-with-query-strings-in-blazor/
I just put more types:
public static class NavigationManagerExtensions
{
public static bool TryGetQueryString<T>(this NavigationManager navManager, string key, out T value)
{
var uri = navManager.ToAbsoluteUri(navManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(key, out var valueFromQueryString))
{
if (typeof(T) == typeof(int) && int.TryParse(valueFromQueryString, out var valueAsInt))
{
value = (T)(object)valueAsInt;
return true;
}
if (typeof(T) == typeof(int?) && int.TryParse(valueFromQueryString, out var valueAsNullableInt))
{
value = (T)(object)valueAsNullableInt;
return true;
}
if (typeof(T) == typeof(bool) && bool.TryParse(valueFromQueryString, out var valueAsBool))
{
value = (T)(object)valueAsBool;
return true;
}
if (typeof(T) == typeof(bool?) && bool.TryParse(valueFromQueryString, out var valueAsNullableBool))
{
value = (T)(object)valueAsNullableBool;
return true;
}
if (typeof(T) == typeof(string))
{
value = (T)(object)valueFromQueryString.ToString();
return true;
}
if (typeof(T) == typeof(decimal) && decimal.TryParse(valueFromQueryString, out var valueAsDecimal))
{
value = (T)(object)valueAsDecimal;
return true;
}
if (typeof(T) == typeof(decimal?) && decimal.TryParse(valueFromQueryString, out var valueAsNullableDecimal))
{
value = (T)(object)valueAsNullableDecimal;
return true;
}
}
value = default;
return false;
}
}
regarding the: "Dealing with updates to query string values" part... I did like so:
<a class="dropdown-item" @onclick='() => GotoLink("thepage?intValue=0&boolValue=true&stringValue=blahBlah")'>goGoGo</a>
and the GotoLink method is this:
private void GotoLink(string url)
{
NavManager.NavigateTo(url, forceLoad: true);
}
by the way the route of the component is cleaner:
@page "/ThePage"
/confirmemail/{Token}/{UserId}
doesn't contain query parameters, it contains route parameters, these are two completely different things. You should be using query parameters, so take out/{Token}/{UserId}
from your@page
directive and follow Antonio Correia's answer.