Blazor Custom Route Constraints
See original GitHub issueI am trying to use custom route constraint in Blazor, similar to how it currently works for both razor pages and MVC routes:
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:
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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:23
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Constraining route parameters
It's not currently possible to constrain a parameter to match a value of an enum. Custom constraints. It is not possible to define...
Read more >ASP.NET Core Blazor routing and navigation
Route templates · Focus an element on navigation · Provide custom content when content isn't found · Route to components from multiple assemblies ......
Read more >Can you customize route constraints in blazor routing
Accepting Henk's answer: No, currently not possible without writing a custom router... use "OnParameterSet".
Read more >How do you implement the routing constraints in Blazor?
A route constraint enforces type matching on a route segment to a component. In the following example, the route to the Users component...
Read more >Creating Custom Constraints For Razor Pages Routes
Razor Page already includes a wide range of constraints that can be used to help disambiguate routes. It is also possible for you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Regex route constraints would be wonderful. Trying to constrain a string route parameter to a finite list of string values and want to 404 otherwise.
@pranavkm I would like to remind you of this, it is quite an important and useful thing.