MyNavigationManager.Uri
#> https://localhost:5001/counter/3?q=hi
MyNavigationManager.BaseUri`
#> https://localhost:5001/
MyNavigationManager.NavigateTo("http://new location")
#> Navigates to new location
MyNavigationManager.LocationChanged
#> An event that fires when the navigation location has changed.
MyNavigationManager.ToAbsoluteUri("pepe")
#> https://localhost:5001/pepe
MyNavigationManager.ToBaseRelativePath( MyNavigationManager.BaseUri)
#> counter/3?q=hi
Helper: AddQueryParm( "q2", "bye" )
#> https://localhost:5001/counter/3?q=hi&q2=bye
Helper: GetQueryParm( "q" )
#> hi
@code {
[Parameter]
public string Id { get; set; }
// blazor: add parm to url
string AddQueryParm(string parmName, string parmValue)
{
var uriBuilder = new UriBuilder(MyNavigationManager.Uri);
var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
q[parmName] = parmValue;
uriBuilder.Query = q.ToString();
var newUrl = uriBuilder.ToString();
return newUrl;
}
// blazor: get query parm from url
string GetQueryParm(string parmName)
{
var uriBuilder = new UriBuilder(MyNavigationManager.Uri);
var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
return q[parmName] ?? "";
}
}