Blazor Custom Route Constraints
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
I am trying to use custom route constraint in Blazor, similar to how it currently works for both [razor pages and MVC routes](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-5.0#custom-route-constraints):
```cs
services.AddRouting(options =>
{
options.ConstraintMap.Add("customName", typeof(MyCustomConstraint));
});
```
... but it appears that blazor route constraints do not consider any custom constraints that have been registered:
https://github.com/dotnet/aspnetcore/blob/af7c0cc2a2f944811041b55f9b4e0ae6cc948fd7/src/Components/Components/src/Routing/RouteConstraint.cs#L57-L85
So I instead encounter the ArgumentException, "Unsupported constraint '{constraint}' in route '{template}'.".
It would be ideal if `RouteConstraint` could be modified to reference `RouteOptions.ContraintMap` as the other routing engines do. Alternatively, needing to use some Blazor-specific registration method to register constraints only for Blazor would also be acceptable.
Contributor guide
Assessment
This issue has not been assessed yet.