Search code examples
blazorasp.net-mvc-routing

Can you customize route constraints in blazor routing


We have this strange construct where some of our domain objects have an ID based on an 18 character string. Is there a way to add a route constraint to match a string only if it matches a certain length / format? As it stands, any string may be passed.

I know I can do it with "OnParameterSet" and check the parameter value, but I'd rather do it something like:

@page "/Account/{AccountSID:StringID}"
<h3>AccountDetails</h3>
<div>@AccountSID</div>

@code {
    [Parameter] public string AccountSID { get; set; }
}

Solution

  • Accepting Henk's answer:

    No, currently not possible without writing a custom router...

    use "OnParameterSet"