Multiple query string parameters in Blazor routing

Solution 1:

For anyone interested in how to pass and get the parameters in the query string style

http://localhost:50466/confirmemail?Token=SomeReallyLargeToken&UserId=SomeGuidUserId

the page route doesn't change

@page "/confirmemail/"

and you should get the parameters like

protected override void OnInitialized()
{
     var uri = navigationManager.ToAbsoluteUri(navigationManager.Uri); //you can use IURIHelper for older versions

     if(QueryHelpers.ParseQuery(uri.Query).TryGetValue("Token", out var token))
     {
         var token_par = token.First();
     }

     if(QueryHelpers.ParseQuery(uri.Query).TryGetValue("UserId", out var userid))
     {
         var userid_par = userid.First();
     }
}

Remember to add the following

@inject NavigationManager navigationManager
@using Microsoft.AspNetCore.WebUtilities @*for QueryHelpers*@

I'm using preview-9

Solution 2:

Could you try?

http://localhost:50466/confirmemail/SomeReallyLargeToken/SomeGuidUserId

I think it should work.

UPDATE: If you want to get values exactly from query parameters good example is here https://learn-blazor.com/pages/router/

Solution 3:

This ( /{Token}/{UserId} ) is not a pattern of query string. It is a part of the route template url(route parameters). This is a query string: ?Token=SomeReallyLargeToken&UserId=SomeGuidUserId.

I'm not sure about it, right now, but this may work: http://localhost:50466/confirmemail/SomeReallyLargeToken/SomeGuidUserId

If you wish to access query parameters (not route parameters), you want to use the IUriHelper like this:

var uri = new Uri(UriHelper.GetAbsoluteUri());

Note that you should parse the returned value... I once saw a utility created by the Blazor community that does it.

Hope this helps...