Skip to content
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

Navigation Query Parameters not added to browser URL [WASM] #2672

Open
2 of 16 tasks
VincentH-Net opened this issue Jan 15, 2025 · 1 comment · May be fixed by #2674
Open
2 of 16 tasks

Navigation Query Parameters not added to browser URL [WASM] #2672

VincentH-Net opened this issue Jan 15, 2025 · 1 comment · May be fixed by #2674
Assignees
Labels
area/navigation kind/bug Something isn't working

Comments

@VincentH-Net
Copy link

VincentH-Net commented Jan 15, 2025

Current behavior

In a Uno 5.5 app in the WASM target, when specifying the DataViewMap ToQuery and FromQuery parameters as per this Uno documentation, and then navigating with NavigateDataAsync with the data parameter specified from a viewmodel to another viewmodel, the ToQuery is invoked, the navigation succeeds and the data parameter is injected in the destination viewmodel ctor.

However, the browser URL only contains the destination view route e.g. /EnergyNetwork, not the query URL parameters returned from ToQuery. Apparently the navigation parameter is passed in-memory, and not via (or reflected in) the browser url.

This prevents users from Uno WASM apps that support deep-linking to bookmark app pages as deep links, making the app browser unfriendly.

Expected behavior

As the above linked Uno documentation implies (but not states or illustrates) and as indicated by @kazo0 here, the expected behavior is that the browser URL contains the query parameters after navigating.

I also expect the documentation to clearly state or illustrate the expected behavior, and it would be helpful if there was an example added in the Uno.Samples repo under Navigation, that uses query and/or path parameters used from viewmodel navigation. The only example I found in that repo is using a property of NavigationViewItem in XAML for query parameters (not sure if it works btw):

From Uno.Samples Navigation:
App.xaml.cs
MainPage.xaml

How to reproduce it (as minimally and precisely as possible)

@kazo0 already created a minimal repro and kindly offered to attach it here

Relevant code snippets from my app:

public static class Routes
{
    public static void Register(IViewRegistry views, IRouteRegistry routes)
    {
        _ = views.Register(
            new ViewMap(ViewModel: typeof(ShellViewModel)),
            new ViewMap<LoginPage, LoginViewModel>(),
            new ViewMap<HomePage, HomeViewModel>(),
            new DataViewMap<EnergyNetworkPage, EnergyNetworkViewModel, EnergyNetworkItem>(
                ToQuery: energyNetworkItem => {
                    energyNetworkItem.Log().LogInformation("ToQuery EnergyNetworkItem {Id}", energyNetworkItem.Id);
                    return new Dictionary<string, string>() { { nameof(EnergyNetworkItem.Id), energyNetworkItem.Id } };
                },
                FromQuery: (sp, query) => Task.FromResult<EnergyNetworkItem?>(new () { Id = (string)query[nameof(EnergyNetworkItem.Id)] })
            )
        );

        _ = routes.Register(
            new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
                Nested:
                [
                    new RouteMap("Login", View: views.FindByViewModel<LoginViewModel>()),
                    new RouteMap("Home", View: views.FindByViewModel<HomeViewModel>()),
                    new RouteMap("EnergyNetwork", View: views.FindByViewModel<EnergyNetworkViewModel>(), DependsOn: "Home"])
                ]
            )
        );
    }
}
public partial class HomeViewModel(INavigator navigator) : BaseViewModel
{
    [RelayCommand]
    async Task NavigateToNetwork(EnergyNetworkItem network) => _ = await navigator.NavigateDataAsync(this, data: network);
}

public partial class EnergyNetworkViewModel(EnergyNetworkItem network) : BaseViewModel
{
    //...
}

Environment

Nuget Package (s), Package Version(s):

{
  "sdk": {
    "version": "8.0.401"
  },
  "msbuild-sdks": {
    "Uno.Sdk": "5.5.54"
  }
}

Affected platform(s):

  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Android
  • WebAssembly
  • Windows
  • Skia (WPF)
  • Skia (GTK on Linux/macOS/Windows)
  • Skia (Linux Framebuffer)
  • Build tasks

Visual Studio:

  • 2019 (version: )
  • 2022 (version: 17.11.4)
  • Visual Studio Code (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

@VincentH-Net VincentH-Net added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification. labels Jan 15, 2025
@kazo0 kazo0 added area/navigation and removed triage/untriaged Indicates an issue requires triaging or verification. labels Jan 15, 2025
@kazo0
Copy link
Contributor

kazo0 commented Jan 15, 2025

Based on initial investigation, the BrowserAddressBarService is properly subscribing to Route changes but the Route that is part of the event args does not have its Data property properly set with the original query parameters from the navigation's ToQuery result. This results in the route.Query() returning null

Changing this line to be: var responseRequest = navSegment with { Qualifier = route.Qualifier, Data = route.Data }; properly includes the data parameters to the BrowserAddressBarService and the url is properly displayed with the query parameters in the browser

@eriklimakc eriklimakc linked a pull request Jan 16, 2025 that will close this issue
7 tasks
@eriklimakc eriklimakc self-assigned this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/navigation kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants