-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor Custom Route Constraints #28938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Extensible route constraints should be a must (and I thought that was already solved in asp.net ~12/13 years ago). Just imagine some route like: Yes, it could be solved by creating -yet another component- and either redirect or include the One more scenario (which I used in razor pages/webapi/MVC a lot) is having short guids as parameters (while internally using Again, nothing that can't be "hacked away", but this is basic, and I'm sure many people (even those not on this thread) would miss this, so I believe |
After 2 hours of debugging why my ulong constraint isn't working, I stumbled upon this bug. |
I believe this should be introduced in ASP.NET Core 7 |
@pranavkm I would like to remind you of this, it is quite an important and useful thing. |
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. |
It'd be super useful if you depend on enum in routes, too. It's a case in my project https://stalcraftclan.com - and currently I have to work it around by grabbing string and manually trying to parse the value. It results in a lot of boilerplate code and is also quite error-prone. It's supported in other ASP.NET Core areas, I don't see why it couldn't be in Blazor. |
This would be really really useful to have, for example when I want to allow just a couple string values (a enum basically). |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
It appears that folks are tone deaf. This is a requested requirement and now it appears not even 'short' is supported. I fail to understand why foundational issues like this keep getting put to the back burner. |
Hello, |
This ticket is nearly 3 years old and a very basic feature. I wouldn't bet they will fix this anytime soon. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
yep for sure would like this feature. Looking to be able to have locale codes embedded into urls as way to support direct links for desired languages etc. domain.com/{locale?}/myPage |
I just spent a few hours trying to figure out why my constraint doesn't work... at least now I know. But please, support such a basic feature. I am very suprised it is not supported for blazor. |
here is working solution for ulong data type, works fine: Route constraint:
Register:
Use:
|
It looked promising, and I am trying this approach (works in server-side WebApi), but in my Blazor WASM I am getting an exception:
Even though I have:
and
|
are you sure you registered RouteOptions for WASM project as well? |
Absolutely, That's from my actual code. I have put a breakpoint at the |
Can not help you here. |
You can confirm that you are using in a Blazor WebAssembly standalone (not interactive WebAssembly ) and it is working for you? |
Currently I don't have solution running anymore, but I used it in WASM client with .net Core app as a server. |
Above solution doesnt seem to work if setting the rendermode on e.g.
It seems in interactive mode, even with constraints defined in program.cs, the router component seems to set up a brand new DefaultInlineConstraintResolver, discarding our custom-mapped constaints. Is there anyway around this huge limitation (Besides removing all custom constraints and verifying the validity of the passed argument within onparametersset? I just want the app to display a loading spinner instead of pre-rendering the entire app just for it to be thrown away seconds later. |
I am trying to use custom route constraint in Blazor, similar to how it currently works for both razor pages and MVC routes:
... but it appears that blazor route constraints do not consider any custom constraints that have been registered:
aspnetcore/src/Components/Components/src/Routing/RouteConstraint.cs
Lines 57 to 85 in af7c0cc
So I instead encounter the ArgumentException, "Unsupported constraint '{constraint}' in route '{template}'.".
It would be ideal if
RouteConstraint
could be modified to referenceRouteOptions.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.The text was updated successfully, but these errors were encountered: