MobileBlazorBindings
MobileBlazorBindings copied to clipboard
Shell Navigation does not support parameters in the middle of URL path
STR:
- Add ContentPage with
@page /users/{Id}/details
- Invoke
await NavigationManager.GoToAsync($"/users/{userId}/details")
ER: Page is opened.
AR: Exception: Value cannot be null. Parameter name: match.
Changing the URL to something like /user-details/{Id}
resolves the issue.
Tagging @lachlanwgordon .
I think this was a deliberate omission when @lachlanwgordon first added Shell because we thought it better to get something checked in, and resolve everything else whenever it was needed.
I think the main reason we didn't support this is that the route logic is re-implemented in MBB because we were sure if we could re-use Blazor's routing logic (such as parsing, etc.).
If it's possible to re-use Blazor's routing logic, that would be ideal, because it would have 100% fidelity between MBB and the rest of Blazor. If we have to re-implement parsing logic then I want to tread very carefully because I don't want to end up with a huge chunk of copied code, or, worse, code that is re-written but incompatible.
Here's a meta-issue where @lachlanwgordon enumerated several limitations with what we currently have: https://github.com/dotnet/MobileBlazorBindings/issues/157
But I think it's fine to have this specific issue open for this specific problem.
I never even thought to try a URL like that, but I'm not at all surprised that it throws an exception.
It's probably not too hard to fix, but unless we urgently need it, let's leave it as-is and try to workout how to use the ASP.Net url parsing.
Thanks for the tip though, I'm going to start using urls like this in web blazor projects.
If it's possible to re-use Blazor's routing logic, that would be ideal, because it would have 100% fidelity between MBB and the rest of Blazor.
Problem is that most of Blazor's routing classes are internal. I'm not sure we'll be able to re-use them. E.g. https://source.dot.net/#Microsoft.AspNetCore.Components/Routing/RouteTableFactory.cs