I am using DotVVMâs routing system with optional parameters like /products/{category?} and noticed strange behavior when the parameter value includes a dash (e.g., âhome-appliancesâ). The route either doesnât match / falls back to the default page; even though manually navigating to the URL should work.
I have confirmed that the parameter gets passed correctly when the value is a single word (like âelectronicsâ); but using slugs with hyphens which are common in SEO-friendly URLs seems to break parameter binding. I suspect it has to do with how DotVVM parses & binds the optional segments. Checked Overview | DotVVM DocumentationSelenium Course Online guide related to this and found it quite informative.
Is there a way to configure DotVVMâs routing system to safely accept hyphenated strings in optional parameters without breaking route resolution? Or do I need to encode these manually and decode them in the viewmodel?
Hi! This looks like a bug on our side, dashes should be normally allowed in the parameters (only slashes / should be restricted). However, Iâm unable to replicate the problem in my setup. Could you please share more details on the exact setup? (i.e. an example code which reproduces the problem.). Is this the only route with the problem, or do other routes have the same behavior of not accepting dashes in path?
Can you reproduce it with this minimal setup?
var route = new DotvvmRoute("products/{category?}", null, "testpage", null, null, configuration);
IDictionary<string, object> parameters;
Assert.IsTrue(route.IsMatch("products/home-appliances", out parameters));
In any case, you can probably workaround it before we can figure what is going on: If the parameter works fine when not optional, you can register two routes for one page: one with the parameter and one without, emulating the maybe-broken DotVVM optional parameter handling.