negative route parameter not allowed
Having the following route:
@page "/sendemail/{RoomName}/{RoomId:int}"
I get the following error:
Uncaught (in promise) Error: System.InvalidOperationException: 'Router' cannot find any component with a route for '/confirmemail/2.01/-1'.
when trying to send a negative RoomId.
No Problem with positive Ids or 0
Are to trying to open page:
/sendemail/2.01/-1
and error says that it cannot find
/confirmemail/2.01/-1
?
I can confirm that negative integer (and long) dosn't work. This is a bug in Blazor - read below I created this simple page:
@page "/sendemail/{RoomName}/{RoomId:int}"
<p>RoomName: @RoomName</p>
<p>RoomId: @RoomId</p>
@functions {
[Parameter] protected string RoomName { get; set; }
[Parameter] protected int RoomId { get; set; }
}
and these links on main page
@page "/"
<a href="/sendemail/-my-room/1">Room 1</a>
<br />
<a href="/sendemail/-my-room/-1">Room -1</a>
First one works as expected, second one throws.
Please note there is no problem with leading dash in the RoomName segment.
Bugs are here https://github.com/aspnet/Blazor/blob/master/src/Microsoft.AspNetCore.Blazor/Routing/RouteConstraint.cs#L65 and here https://github.com/aspnet/Blazor/blob/master/src/Microsoft.AspNetCore.Blazor/Routing/RouteConstraint.cs#L68
To be consistent with decimal, double and float you should use NumberStyles.Integer instead of NumberStyles.None. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.numberstyles?view=netcore-2.1
I'm able to reproduce this as well.
blazor.webassembly.js:1 Uncaught (in promise) Error: System.InvalidOperationException: 'Router' cannot find any component with a route for '/test/123/-1'.
at Microsoft.AspNetCore.Blazor.Routing.Router.Refresh () <0x1c3d830 + 0x000b4> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Routing.Router.SetParameters (Microsoft.AspNetCore.Blazor.Components.ParameterCollection parameters) <0x1bbc6c0 + 0x0003e> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 frameIndex) <0x1b45bf0 + 0x00082> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 frameIndex) <0x1b45a60 + 0x0008a> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.InsertNewFrame (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 newFrameIndex) <0x1b45740 + 0x000ca> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 oldStartIndex, System.Int32 oldEndIndexExcl, System.Int32 newStartIndex, System.Int32 newEndIndexExcl) <0x1b44ed8 + 0x0024a> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.ComputeDiff (Microsoft.AspNetCore.Blazor.Rendering.Renderer renderer, Microsoft.AspNetCore.Blazor.Rendering.RenderBatchBuilder batchBuilder, System.Int32 componentId, Microsoft.AspNetCore.Blazor.RenderTree.ArrayRange`1[T] oldTree, Microsoft.AspNetCore.Blazor.RenderTree.ArrayRange`1[T] newTree) <0x1b416c0 + 0x000a6> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.ComponentState.RenderIntoBatch (Microsoft.AspNetCore.Blazor.Rendering.RenderBatchBuilder batchBuilder, Microsoft.AspNetCore.Blazor.RenderFragment renderFragment) <0x1b3eb68 + 0x000b8> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.Renderer.RenderInExistingBatch (Microsoft.AspNetCore.Blazor.Rendering.RenderQueueEntry renderQueueEntry) <0x1b3e790 + 0x00040> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.Renderer.ProcessRenderQueue () <0x1b3df30 + 0x00048> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.Renderer.AddToRenderQueue (System.Int32 componentId, Microsoft.AspNetCore.Blazor.RenderFragment renderFragment) <0x1b2c848 + 0x0006e> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Components.RenderHandle.Render (Microsoft.AspNetCore.Blazor.RenderFragment renderFragment) <0x1b2c530 + 0x0003a> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Components.BlazorComponent.StateHasChanged () <0x1b2c438 + 0x00048> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Components.BlazorComponent.SetParameters (Microsoft.AspNetCore.Blazor.Components.ParameterCollection parameters) <0x1b33010 + 0x000e0> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRenderer.AddComponent (System.Type componentType, System.String domElementSelector) <0x1ac82f8 + 0x00090> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyBlazorApplicationBuilder.CreateRenderer () <0x1aa9878 + 0x00078> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyHost.StartAsync (System.Threading.CancellationToken cancellationToken) <0x1a8e008 + 0x0010c> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyHostExtensions.Run (Microsoft.AspNetCore.Blazor.Hosting.IWebAssemblyHost host) <0x1a8d788 + 0x00020> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at WebApplication1.Program.Main (System.String[] args) [0x00001] in C:\Users\daroth\Source\Repos\WebApplication1\WebApplication1\Program.cs:9
at Microsoft.AspNetCore.Blazor.Routing.Router.Refresh () <0x1c3d830 + 0x000b4> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Routing.Router.SetParameters (Microsoft.AspNetCore.Blazor.Components.ParameterCollection parameters) <0x1bbc6c0 + 0x0003e> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 frameIndex) <0x1b45bf0 + 0x00082> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 frameIndex) <0x1b45a60 + 0x0008a> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.InsertNewFrame (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 newFrameIndex) <0x1b45740 + 0x000ca> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange (Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder+DiffContext& diffContext, System.Int32 oldStartIndex, System.Int32 oldEndIndexExcl, System.Int32 newStartIndex, System.Int32 newEndIndexExcl) <0x1b44ed8 + 0x0024a> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeDiffBuilder.ComputeDiff (Microsoft.AspNetCore.Blazor.Rendering.Renderer renderer, Microsoft.AspNetCore.Blazor.Rendering.RenderBatchBuilder batchBuilder, System.Int32 componentId, Microsoft.AspNetCore.Blazor.RenderTree.ArrayRange`1[T] oldTree, Microsoft.AspNetCore.Blazor.RenderTree.ArrayRange`1[T] newTree) <0x1b416c0 + 0x000a6> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.ComponentState.RenderIntoBatch (Microsoft.AspNetCore.Blazor.Rendering.RenderBatchBuilder batchBuilder, Microsoft.AspNetCore.Blazor.RenderFragment renderFragment) <0x1b3eb68 + 0x000b8> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.Renderer.RenderInExistingBatch (Microsoft.AspNetCore.Blazor.Rendering.RenderQueueEntry renderQueueEntry) <0x1b3e790 + 0x00040> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.Renderer.ProcessRenderQueue () <0x1b3df30 + 0x00048> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Rendering.Renderer.AddToRenderQueue (System.Int32 componentId, Microsoft.AspNetCore.Blazor.RenderFragment renderFragment) <0x1b2c848 + 0x0006e> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Components.RenderHandle.Render (Microsoft.AspNetCore.Blazor.RenderFragment renderFragment) <0x1b2c530 + 0x0003a> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Components.BlazorComponent.StateHasChanged () <0x1b2c438 + 0x00048> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Components.BlazorComponent.SetParameters (Microsoft.AspNetCore.Blazor.Components.ParameterCollection parameters) <0x1b33010 + 0x000e0> in <5fb27225b9c7403e87df81958625363e>:0
at Microsoft.AspNetCore.Blazor.Browser.Rendering.BrowserRenderer.AddComponent (System.Type componentType, System.String domElementSelector) <0x1ac82f8 + 0x00090> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyBlazorApplicationBuilder.CreateRenderer () <0x1aa9878 + 0x00078> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyHost.StartAsync (System.Threading.CancellationToken cancellationToken) <0x1a8e008 + 0x0010c> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at Microsoft.AspNetCore.Blazor.Hosting.WebAssemblyHostExtensions.Run (Microsoft.AspNetCore.Blazor.Hosting.IWebAssemblyHost host) <0x1a8d788 + 0x00020> in <57e79dbc0ddc403bb6b3264cb6abd890>:0
at WebApplication1.Program.Main (System.String[] args) [0x00001] in C:\Users\daroth\Source\Repos\WebApplication1\WebApplication1\Program.cs:9
at Object.callMethod (blazor.webassembly.js:1)
at Object.callEntryPoint (blazor.webassembly.js:1)
at blazor.webassembly.js:1
at blazor.webassembly.js:1
at Object.next (blazor.webassembly.js:1)
at i (blazor.webassembly.js:1)
Hi, this looks intuitive. Can I take it as my first issue to this repository.
Thanks for reporting it! Yes, should be a good first issue. Thanks for your interest, @KristianJakubik!
@KristianJakubik, Please also provide tests 😄