Told to copy you in @guardrex
[Enter feedback here]
The Docs page for routing is only covering route parameters. Imo it should cover query parameters as well as this is an important part of dealing with URLs..
To parse query parameters currently, one needs to do the following:
1) Install WebUtilities package, like so dotnet add package Microsoft.AspNetCore.WebUtilities
2) Write code to parse query parameters, e.g:
if (Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue("page", out var param))
{
this.pageParam = param;
}
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Thanks @softchris ... We'll consider it on the next round of issue triage, which usually happens on Fridays.
Cross-references to related engineering issues:
var currentQuery = new Uri(Navigation.Uri).Query;@guardrex Chris has some time to create a PR for this issue. Are you okay with him moving forward?
Of course, @softchris, you're welcome to submit the PR, but I recommend waiting until @mkArtakMSFT triages this issue and we determine the best thing to show. The following is from another example that we have, which might be good to show along with what you will want to add for getting the exact values out. Sometimes, the dev just wants the whole query string for other reasons.
var currentQuery = new Uri(Navigation.Uri).Query;
Also, I have a vague recollection of this coming up before. I'll need to research it and see. I sort of have the impression that they didn't want to cover it. I'll have to check. Give me a bit longer. I'm buried in another issue at the moment. I'll take a look right after I'm done with this current task.
Wait for Artak to respond, but here are some recommendations for when you work this ...
https://github.com/dotnet/aspnetcore/issues/5489 was closed without a new engineering issue that pertains to doing anything special for query strings, so it seems like devs will use WebUtilities. At the time I responded to a reader's issue, that was still open. It looked like something might have been designed. Seems not to be the case.
Given that this will be for a reference topic, you'll only need to mention and cross-link the NuGet.org package for Microsoft.AspNetCore.WebUtilities at https://www.nuget.org/packages/Microsoft.AspNetCore.WebUtilities. You don't need to describe adding the package to a project. We usually do that in tutorials.
Show any inject directives and required using directives in your sample. It's ok to use an ellipsis between them and the lines of code. You don't need to show a method ... you can jump right to the line(s) of code right after the ellipsis appears (see my example below).
Recommend this for a new section at the end of the topic. That way, the reader has already consumed the NavigationManger coverage.
I recommend that you mention ...
@inject NavigationManager Navigation
...
var currentQuery = new Uri(Navigation.Uri).Query;
... as an approach to grab the query string _either_ as a paragraph and example for the end of the URI and navigation state helpers section or in the new section that you add.
@mkArtakMSFT Any thoughts? I don't want to wait too much longer, as Chris has time right now to work on this.
If Chris doesn't have time, assign me and mark this a P1 for fastest service 🏃. I'm actually working in the P2 area right now, so this would be addressed quickly after I have your, Artak, feedback on the direction to take with it.
@guardrex hi Luke, feel free to go at it :)