{"id":56435,"date":"2021-01-11T08:00:39","date_gmt":"2021-01-11T07:00:39","guid":{"rendered":"https:\/\/code-maze.com\/?p=56435"},"modified":"2021-12-24T12:48:33","modified_gmt":"2021-12-24T11:48:33","slug":"query-strings-blazor-webassembly","status":"publish","type":"post","link":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/","title":{"rendered":"How to Use Query Strings in Blazor WebAssembly"},"content":{"rendered":"<p>In this article, we are going to learn how to use query strings in Blazor WebAssembly. We are going to show you how to send query strings to the Blazor component and also how to read them inside the component.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit the <a href=\"https:\/\/github.com\/CodeMazeBlog\/blazor-wasm-query-strings\" target=\"_blank\" rel=\"nofollow noopener\">Query Strings in Blazor WebAssembly<\/a> repository<\/div>\n<p>So, let&#8217;s start.<\/p>\n<h2 id=\"project-preparation\">Project Preparation<\/h2>\n<p>We are going to create a new Blazor WebAssembly project:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/01-Blazor-WebAssembly-Project-Creation.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56437\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/01-Blazor-WebAssembly-Project-Creation.png\" alt=\"Blazor WebAssembly Project Creation\" width=\"942\" height=\"615\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/01-Blazor-WebAssembly-Project-Creation.png 942w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/01-Blazor-WebAssembly-Project-Creation-300x196.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/01-Blazor-WebAssembly-Project-Creation-768x501.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/a><\/p>\n<p>As soon as we create this project, we are going to create a new <code>QueryStringDisplayDemo<\/code> component under the <code>Pages<\/code> folder:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/02-Query-Strings-in-Blazor-WebAssembly-example-demo-component.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56438\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/02-Query-Strings-in-Blazor-WebAssembly-example-demo-component.png\" alt=\"Query Strings in Blazor WebAssembly example demo component\" width=\"305\" height=\"140\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/02-Query-Strings-in-Blazor-WebAssembly-example-demo-component.png 305w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/02-Query-Strings-in-Blazor-WebAssembly-example-demo-component-300x138.png 300w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/a><\/p>\n<p>For now, we are just going to add a route to this component:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-highlight=\"1\">@page \"\/query-string-display\"\r\n\r\n&lt;h3&gt;QueryStringDisplayDemo&lt;\/h3&gt;\r\n\r\n@code {\r\n\r\n}<\/pre>\n<p>We are going to use this component to show you how to read and display query strings in Blazor WebAssembly.<\/p>\n<p>But first, we have to send the query string parameters to it.<\/p>\n<h2 id=\"sending-query-strings\">Sending Query Strings in Blazor WebAssembly<\/h2>\n<p>We can send query string parameters in multiple ways in Blazor WebAssembly.<\/p>\n<p>The first way is the common one we use in any HTML page with an anchor element. To show it, let&#8217;s modify the <code>Index.razor<\/code> component:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">@page \"\/\"\r\n\r\n&lt;h1&gt;Hello, world!&lt;\/h1&gt;\r\n\r\nWelcome to your new app.\r\n\r\n&lt;p&gt;\r\n    Click &lt;a href=\"query-string-display?name=John\"&gt;here&lt;\/a&gt; \r\n    to send a query string parameter to the component.\r\n&lt;\/p&gt;<\/pre>\n<p>Basically, we use the anchor element with the <code>href<\/code> attribute to navigate to the <code>QueryStringDisplayDemo<\/code> component and pass a single query string parameter to it. If we start the app, we are going to see a link on the Home page:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/03-Using-anchor-element-to-send-query-strings-in-Blazor-WebAssembly-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-56441 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/03-Using-anchor-element-to-send-query-strings-in-Blazor-WebAssembly-1.png\" alt=\"Using anchor element to send query strings in Blazor WebAssembly\" width=\"905\" height=\"275\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/03-Using-anchor-element-to-send-query-strings-in-Blazor-WebAssembly-1.png 905w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/03-Using-anchor-element-to-send-query-strings-in-Blazor-WebAssembly-1-300x91.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/03-Using-anchor-element-to-send-query-strings-in-Blazor-WebAssembly-1-768x233.png 768w\" sizes=\"auto, (max-width: 905px) 100vw, 905px\" \/><\/a><\/p>\n<p>As soon as we click the link, the app redirects us to the <code>QueryStringDisplayDemo<\/code> component with the query parameter applied to the URI:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-56440 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453.png\" alt=\"Query string parameter inside the URI\" width=\"703\" height=\"179\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453.png 703w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453-300x76.png 300w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/a><\/p>\n<p>Good.<\/p>\n<p>Now, this is a manual way of passing query string parameters to a component. But sometimes we have to execute some sort of business logic and then create our URI with query parameters. In these situations, it is obvious that we can&#8217;t hardcode query strings inside the URI. What we can do is use the <code>NavigationManager<\/code> service.<\/p>\n<p>Let&#8217;s see how to do that.<\/p>\n<h3>Using WebUtilities and NavigationManager<\/h3>\n<p>Before we start, we have to install the <code>Microsoft.AspNetCore.WebUtilities<\/code> package:<\/p>\n<p><code>PM&gt; Install-Package Microsoft.AspNetCore.WebUtilities -Version 2.2.0<\/code><\/p>\n<p>This is a great library that helps us working with forms, multipart messages, and query strings.<\/p>\n<p>After the installation, we can modify the <code>Index.razor<\/code> file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"2-3, 14-17, 19-29\">@page \"\/\"\r\n@using Microsoft.AspNetCore.WebUtilities\r\n@inject NavigationManager NavManager\r\n\r\n&lt;h1&gt;Hello, world!&lt;\/h1&gt;\r\n\r\nWelcome to your new app.\r\n\r\n&lt;p&gt;\r\n    Click &lt;a href=\"query-string-display?name=John\"&gt;here&lt;\/a&gt;\r\n    to send a query string parameter to the component.\r\n&lt;\/p&gt;\r\n\r\n&lt;p&gt;\r\n    Click the button to send a query string parameter with NavigationManager\r\n    &lt;button type=\"button\" class=\"btn btn-info\" @onclick=\"Navigate\"&gt;Send&lt;\/button&gt;\r\n&lt;\/p&gt;\r\n\r\n@code {\r\n    private void Navigate()\r\n    {\r\n        var queryParams = new Dictionary&lt;string, string&gt;\r\n        {\r\n            [\"name\"] = \"John\"\r\n        };\r\n\r\n        NavManager.NavigateTo(QueryHelpers.AddQueryString(\"query-string-display\", queryParams));\r\n    }\r\n}<\/pre>\n<p>In the HTML part, we add a <code>using<\/code> directive for the <code>WebUtilities<\/code> namespace and inject the <code>NavigationManager<\/code> service. Also, we create an HTML markup with a single button with a <code>@onclick<\/code> event. Then in the code part, we create a <code>Navigate<\/code> method. Inside we create a single dictionary and populate it with our query parameter. Finally, we use the NavigationManager&#8217;s <code>NavigateTo<\/code> method to navigate the user to the required location. The <code>QueryHelpers.AddQueryString<\/code> method, which comes from the <code>WebUtilities<\/code> package, helps us adding the query string parameter to the URI.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To learn more about the Routing and NavigationManager in Blazor WebAssembly, you can read our <a href=\"https:\/\/code-maze.com\/blazor-routing-page-directive-navigation-manager-nav-links\/\" target=\"_blank\" rel=\"noopener noreferrer\">Routing in Blazor WebAssembly<\/a> article. Also, you can use the <code>Microsoft.AspNetCore.WebUtilities<\/code> package to send query string to the server as we did in our <a href=\"https:\/\/code-maze.com\/blazor-webassembly-pagination\/\" target=\"_blank\" rel=\"noopener noreferrer\">Paging<\/a>, <a href=\"https:\/\/code-maze.com\/blazor-webassembly-sorting\/\" target=\"_blank\" rel=\"noopener noreferrer\">Sorting<\/a>, and <a href=\"https:\/\/code-maze.com\/blazor-webassembly-searching\/\" target=\"_blank\" rel=\"noopener noreferrer\">Searching<\/a> articles in Blazor WebAssembly.<\/div>\n<p>Now, if we start our app, and click the button, we are going to see the same result as we did with the previous example:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56440\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453.png\" alt=\"Query string parameter inside the URI\" width=\"703\" height=\"179\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453.png 703w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/04-Query-string-parameter-inside-the-URI-e1605521749453-300x76.png 300w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/a><\/p>\n<p>Excellent.<\/p>\n<p>Now it&#8217;s time to learn how to read query strings in Blazor WebAssembly.<\/p>\n<h2 id=\"reading-query-strings\">Reading Query Strings in Blazor WebAssembly<\/h2>\n<p>To show you how to read query strings in Blazor WebAssembly, we are going to modify the <code>QueryStringDisplayDemo<\/code> component:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"2-3, 8, 10-23\">@page \"\/query-string-display\"\r\n@using Microsoft.AspNetCore.WebUtilities\r\n@inject NavigationManager NavManager\r\n\r\n&lt;h3&gt;QueryStringDisplayDemo&lt;\/h3&gt;\r\n&lt;hr \/&gt;\r\n\r\n&lt;h3&gt;First Name: @_name&lt;\/h3&gt;\r\n\r\n@code {\r\n    private string _name;\r\n\r\n    protected override void OnInitialized()\r\n    {\r\n        var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\r\n\r\n        var queryStrings = QueryHelpers.ParseQuery(uri.Query);\r\n        if(queryStrings.TryGetValue(\"name\", out var name))\r\n        {\r\n            _name = name;\r\n        }\r\n    }\r\n}<\/pre>\n<p>Here we use the same namespace and inject the same service as we did in a previous example. Also, we display the value of the <code>_name<\/code> field on the page. In the code part, we create a private <code>_name<\/code> field and also convert the <code>NavManager.Uri<\/code> property of the string type to the <code>Uri<\/code> object with the <code>ToAbsoluteUri<\/code> method. The <code>Uri<\/code> class provides an object representation of URI and enables us to use all kinds of properties like Query, PathAndQuery, IsAbsoluteUri, etc.<\/p>\n<p>After the conversion, we extract the query parameter with the <code>QueryHelpers.ParseQuery<\/code> method where we pass the <code>uri.Query<\/code> property as an argument. This expression returns <code>Dicrtionary&lt;string, StringValues&gt;<\/code> as a result. Then we use the <code>TryGetValue<\/code> method to extract the value of the query string to the <code>name<\/code> local variable and return a boolean result if extraction succeeded or not. If extraction succeeds, we just assign the value of the <code>name<\/code> local variable to the <code>_name<\/code> field.<\/p>\n<p>Now, if we start the app, and click the link or button, we are going to see the extracted value on the screen:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/05-Reading-query-strings-in-Blazor-WebAssembly.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56445\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/05-Reading-query-strings-in-Blazor-WebAssembly.png\" alt=\"Reading query strings in Blazor WebAssembly\" width=\"752\" height=\"332\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/05-Reading-query-strings-in-Blazor-WebAssembly.png 752w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/05-Reading-query-strings-in-Blazor-WebAssembly-300x132.png 300w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/a><\/p>\n<h3>Using Multiple Query String Parameters<\/h3>\n<p>Of course, this works with multiple parameters as well.<\/p>\n<p>To test this, let&#8217;s modify the <code>Index<\/code> component first:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"10,25\">@page \"\/\"\r\n@using Microsoft.AspNetCore.WebUtilities\r\n@inject NavigationManager NavManager\r\n\r\n&lt;h1&gt;Hello, world!&lt;\/h1&gt;\r\n\r\nWelcome to your new app.\r\n\r\n&lt;p&gt;\r\n    Click &lt;a href=\"query-string-display?name=John&amp;age=26\"&gt;here&lt;\/a&gt;\r\n    to send a query string parameter to the component.\r\n&lt;\/p&gt;\r\n\r\n&lt;p&gt;\r\n    Click the button to send a query string parameter with NavigationManager\r\n    &lt;button type=\"button\" class=\"btn btn-info\" @onclick=\"Navigate\"&gt;Here&lt;\/button&gt;\r\n&lt;\/p&gt;\r\n\r\n@code {\r\n    private void Navigate()\r\n    {\r\n        var queryParams = new Dictionary&lt;string, string&gt;\r\n        {\r\n            [\"name\"] = \"John\",\r\n            [\"age\"] = \"26\"\r\n        };\r\n\r\n        NavManager.NavigateTo(QueryHelpers.AddQueryString(\"query-string-display\", queryParams));\r\n    }\r\n}<\/pre>\n<p>And also the <code>QueryStringDisplayDemo<\/code> file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"9,13,25-28\">@page \"\/query-string-display\"\r\n@using Microsoft.AspNetCore.WebUtilities\r\n@inject NavigationManager NavManager\r\n\r\n&lt;h3&gt;QueryStringDisplayDemo&lt;\/h3&gt;\r\n&lt;hr \/&gt;\r\n\r\n&lt;h3&gt;First Name: @_name&lt;\/h3&gt;\r\n&lt;h3&gt;Age: @_age&lt;\/h3&gt;\r\n\r\n@code {\r\n    private string _name;\r\n    private int _age;\r\n\r\n    protected override void OnInitialized()\r\n    {\r\n        var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\r\n\r\n        var queryStrings = QueryHelpers.ParseQuery(uri.Query);\r\n        if (queryStrings.TryGetValue(\"name\", out var name))\r\n        {\r\n            _name = name;\r\n        }\r\n\r\n        if(queryStrings.TryGetValue(\"age\", out var age))\r\n        {\r\n            _age = Convert.ToInt32(age);\r\n        }\r\n    }\r\n}<\/pre>\n<p>Now we can start the application and press the link or button:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56446\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings.png\" alt=\"Multiple query strings\" width=\"736\" height=\"275\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings.png 736w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings-300x112.png 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/a><\/p>\n<p>We can see both parameters displayed on the page. But let&#8217;s improve this solution a bit.<\/p>\n<h2 id=\"improving-the-solution\">Improving the Solution<\/h2>\n<p>Right now, we have only two query string parameters and the code for reading them isn&#8217;t that long. But what if we had more query parameters? Our code would become repetitive and consequently harder to maintain. To avoid that, we can make a cleaner solution by introducing extension methods.<\/p>\n<p>Let&#8217;s see how to do that.<\/p>\n<p>First, we are going to create a new <code>Extensions<\/code> folder and inside it a new <code>NavigationManagerExtension<\/code> class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static class NavigationManagerExtension\r\n{\r\n    public static T ExtractQueryStringByKey&lt;T&gt;(this NavigationManager navManager, string key)\r\n    {\r\n        var uri = navManager.ToAbsoluteUri(navManager.Uri);\r\n        QueryHelpers.ParseQuery(uri.Query)\r\n            .TryGetValue(key, out var queryValue);\r\n\r\n        if (typeof(T).Equals(typeof(int)))\r\n        {\r\n            int.TryParse(queryValue, out int result);\r\n            return (T)(object)result;\r\n        }\r\n\r\n        if (typeof(T).Equals(typeof(string)))\r\n            return (T)(object)queryValue.ToString();\r\n\r\n        return default;\r\n    }\r\n}<\/pre>\n<p>We extend the <code>NavigationManager<\/code> type and pass a key for the query string parameter we want to extract. Then, we repeat the same logic as we have in our component and also parse the query parameters based on the type we provide for this generic method. Of course, we have only two type checks here because we only have a string and int query parameters, but you can extend this easily.<\/p>\n<p>Now, we can return to the <code>QueryStringDisplayDemo<\/code> component, and modify the <code>@code<\/code> part:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">@code {\r\n    private string _name;\r\n    private int _age;\r\n\r\n    protected override void OnInitialized()\r\n    {\r\n        _name = NavManager.ExtractQueryStringByKey&lt;string&gt;(\"name\");\r\n        _age = NavManager.ExtractQueryStringByKey&lt;int&gt;(\"age\");\r\n    }\r\n}<\/pre>\n<p>As you can see, this is a much better and cleaner solution.<\/p>\n<p>If we test it, we are going to get the same result:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56446\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings.png\" alt=\"Multiple query strings\" width=\"736\" height=\"275\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings.png 736w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/06-Multiple-query-strings-300x112.png 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/a><\/p>\n<p>Also, if we pass a decimal or boolean value instead of int, we will get a default int value for the Age part:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/07-Wrong-query-parameter-value.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-56452\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/07-Wrong-query-parameter-value.png\" alt=\"Wrong query parameter value\" width=\"741\" height=\"325\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/07-Wrong-query-parameter-value.png 741w, https:\/\/code-maze.com\/wp-content\/uploads\/2020\/11\/07-Wrong-query-parameter-value-300x132.png 300w\" sizes=\"auto, (max-width: 741px) 100vw, 741px\" \/><\/a><\/p>\n<p>So, the code is safe as well.<\/p>\n<p>Excellent.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this article, we have learned:<\/p>\n<ul>\n<li>How to send query string parameters from one component to other<\/li>\n<li>The way to read these query string parameters from the destination component<\/li>\n<li>How to extract the read logic into the extension method<\/li>\n<\/ul>\n<p>So, that&#8217;s all for this one.<\/p>\n<p>Until the next one.<\/p>\n<p>Best regards.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn how to use query strings in Blazor WebAssembly. We are going to show you how to send query strings to the Blazor component and also how to read them inside the component. So, let&#8217;s start. Project Preparation We are going to create a new Blazor WebAssembly project: [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":56971,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[683,684,12],"tags":[685,686,708,819],"class_list":["post-56435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blazor","category-blazor-webassembly","category-csharp","tag-blazor","tag-blazor-webassembly","tag-navigationmanager","tag-query-string","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Use Query Strings in Blazor WebAssembly - Code Maze<\/title>\n<meta name=\"description\" content=\"Using query strings in Blazor WebAssembly is quite easy, and we are going to learn how to send and read them in our components.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use Query Strings in Blazor WebAssembly - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Using query strings in Blazor WebAssembly is quite easy, and we are going to learn how to send and read them in our components.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-11T07:00:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-24T11:48:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"How to Use Query Strings in Blazor WebAssembly\",\"datePublished\":\"2021-01-11T07:00:39+00:00\",\"dateModified\":\"2021-12-24T11:48:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\"},\"wordCount\":1036,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png\",\"keywords\":[\"Blazor\",\"Blazor WebAssembly\",\"NavigationManager\",\"Query String\"],\"articleSection\":[\"Blazor\",\"Blazor WebAssembly\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\",\"url\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\",\"name\":\"How to Use Query Strings in Blazor WebAssembly - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png\",\"datePublished\":\"2021-01-11T07:00:39+00:00\",\"dateModified\":\"2021-12-24T11:48:33+00:00\",\"description\":\"Using query strings in Blazor WebAssembly is quite easy, and we are going to learn how to send and read them in our components.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png\",\"width\":1100,\"height\":620,\"caption\":\"query strings in Blazor WebAssembly Featured Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use Query Strings in Blazor WebAssembly\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use Query Strings in Blazor WebAssembly - Code Maze","description":"Using query strings in Blazor WebAssembly is quite easy, and we are going to learn how to send and read them in our components.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/","og_locale":"en_US","og_type":"article","og_title":"How to Use Query Strings in Blazor WebAssembly - Code Maze","og_description":"Using query strings in Blazor WebAssembly is quite easy, and we are going to learn how to send and read them in our components.","og_url":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/","og_site_name":"Code Maze","article_published_time":"2021-01-11T07:00:39+00:00","article_modified_time":"2021-12-24T11:48:33+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"How to Use Query Strings in Blazor WebAssembly","datePublished":"2021-01-11T07:00:39+00:00","dateModified":"2021-12-24T11:48:33+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/"},"wordCount":1036,"commentCount":4,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png","keywords":["Blazor","Blazor WebAssembly","NavigationManager","Query String"],"articleSection":["Blazor","Blazor WebAssembly","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/","url":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/","name":"How to Use Query Strings in Blazor WebAssembly - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png","datePublished":"2021-01-11T07:00:39+00:00","dateModified":"2021-12-24T11:48:33+00:00","description":"Using query strings in Blazor WebAssembly is quite easy, and we are going to learn how to send and read them in our components.","breadcrumb":{"@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/query-strings-blazor-webassembly\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/01\/query-strings-in-Blazor-WASM.png","width":1100,"height":620,"caption":"query strings in Blazor WebAssembly Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/query-strings-blazor-webassembly\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"How to Use Query Strings in Blazor WebAssembly"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/56435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=56435"}],"version-history":[{"count":1,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/56435\/revisions"}],"predecessor-version":[{"id":62149,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/56435\/revisions\/62149"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/56971"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=56435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=56435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=56435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}