I want to use regular expressions inside the Blazor route. I know that in the .Net 8 version of Blazer Web App - this is possible, because I created a template for this app and regular expressions worked there. In the main application I was using Blazer Web Assembly, which I upgraded to WebApp according to Microsoft documentation. But these actions did not work and when I use regular expressions in the route I get this error:
Unhandled exception rendering component: The constraint entry 'doc' - 'regex((.*)(?:\/details)$)' on the route '/{{*doc:regex((.*)(?:\/details)$)}' could not be resolved by the constraint resolver of type 'DefaultInlineConstraintResolver'. System.InvalidOperationException: The constraint entry 'doc' - 'regex((.*)(?:\/details)$)' on the route '/{{*doc:regex((.*)(?:\/details)$)})}' could not be resolved by the constraint resolver of type 'DefaultInlineConstraintResolver'.The route looks like this:
@attribute [Route(@“/{{*doc:regex((.*)(?:\/details)$)$)}”)]] @rendermode InteractiveWebAssembly[Parameter] public string doc { get; set; }Again, this route works in the Blazor template.
Please tell me where I made a mistake?
Program.cs code:
var builder = WebApplication.CreateBuilder(args);builder.Services.AddRazorComponents() .AddInteractiveWebAssemblyComponents();builder.Services.AddControllers();var app = builder.Build();if (app.Environment.IsDevelopment()){ app.UseWebAssemblyDebugging();}else{ app.UseException Handler("/Error"); app.UseHsts();}app.UseHttpsRedirection();app.UseStaticFiles();app.UseAntiforgery();app.MapRazorComponents<App>() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(Client._Imports).Assembly);app.MapControllers();app.Run();