dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 171 forks source link

Shell Navigation does not support parameters in the middle of URL path #324

Open Dreamescaper opened 3 years ago

Dreamescaper commented 3 years ago

STR:

  1. Add ContentPage with @page /users/{Id}/details
  2. 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.

Eilon commented 3 years ago

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.

Eilon commented 3 years ago

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.

lachlanwgordon commented 3 years ago

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.

Dreamescaper commented 3 years ago

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