Skip to content

Navigation RouteNotifier.RouteChanged not invoked #2606

Open

Description

@KWodarczyk

Current behavior

RouteNotifier.RouteChanged is not fired, Application it stuck at loading screen

Expected behavior

RouteNotifier.RouteChanged should fire when navigator.NavigateRouteAsync is called

App.xaml.cs

    private void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
    {
        views.Register(
            new ViewMap(ViewModel: typeof(ShellViewModel)),
            new ViewMap<MainPage, MainViewModel>(),
            new ViewMap<FirstPage, FirstViewModel>(),
            new DataViewMap<SecondPage, SecondViewModel, Entity>()
        );

        routes.Register(
            new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
                Nested:
                [
                    new ("Main", View: views.FindByViewModel<MainViewModel>(),IsDefault:true)
                ]
            )
        );
    }

Main Page xaml

<Page x:Class="UnoAppNavigation2.Presentation.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:UnoAppNavigation2"
      xmlns:Presentation="using:UnoAppNavigation2.Presentation"
      xmlns:uen="using:Uno.Extensions.Navigation.UI"
      xmlns:utu="using:Uno.Toolkit.UI"
      Loaded="Page_Loaded"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

  <Grid uen:Region.Attached="True" RowDefinitions="auto,*">
    <StackPanel Grid.Row="0" HorizontalAlignment="Left" Orientation="Horizontal" Background="DarkSlateGray">
         <TextBlock>
           <Run Text="URL:"/>
           <Run x:Name="UrlPath"/>
         </TextBlock>
    </StackPanel>

        <NavigationView Grid.Row="1"
            uen:Region.Attached="true"
            PaneDisplayMode="Top"
            IsSettingsVisible="False"
            ItemInvoked="NavigationView_ItemInvoked"
            IsBackButtonVisible="Collapsed"
            IsBackEnabled="False">
            <NavigationView.MenuItems>

                <NavigationViewItem
                  Content="One"
                  x:Name="OneTab"
                  uen:Region.Name="{x:Bind local:PageNames.FirstPage}" />

                <NavigationViewItem
                  Content="Two"
                  x:Name="TwoTab"
                  uen:Region.Name="{x:Bind local:PageNames.SecondPage}" />

            </NavigationView.MenuItems>

            <Grid uen:Region.Attached="True"
                  uen:Region.Navigator="Visibility">

              <Presentation:FirstPage Visibility="Collapsed" uen:Region.Name="{x:Bind local:PageNames.FirstPage}"/>
              <Presentation:SecondPage Visibility="Collapsed" uen:Region.Name="{x:Bind local:PageNames.SecondPage}"/>

            </Grid>
        </NavigationView>
    </Grid>
</Page>

Main page that navigates to FirstPage on Loaded

public sealed partial class MainPage : Page
{
    private App? _app;

    public MainViewModel? ViewModel { get; set; }

    public MainPage()
    {
        _app = (Application.Current as App);

        INavigator navigator = this.Navigator();

        this.InitializeComponent();

        UrlPath.Text =  _app?.MainHref + " base url:"+_app.BaseUrl;
    }

    private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
    {
        Console.WriteLine($"==== Navigation invoked =====");
    }

    private async void Page_Loaded(object sender, RoutedEventArgs e)
    {
        var navigator = this.Navigator();
        Console.WriteLine($"====    Navigation to {PageNames.FirstPage} =======");
        var result = await navigator.NavigateRouteAsync(this, PageNames.FirstPage);  //This does not invoke RouteChange
    }
}

First Page that subscribes to RoutChanged event

public sealed partial class FirstPage : Page
{
    private App _app;

    public FirstPage()
    {
        _app = (Application.Current as App);

        this.InitializeComponent();

        var notifier = _app.Host.Services.GetService<IRouteNotifier>();

        notifier.RouteChanged += OnRouteChanged;

        Debug.WriteLine("============= First  Page Ctor ===========");

        Debug.WriteLine($"is Rount NOtifier null ? {notifier is null}");
    }

    private void OnRouteChanged(object? sender, RouteChangedEventArgs e)
    {
        Debug.WriteLine($"===== In First Page route changed to {e.Region.Name}");
    }

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        Console.WriteLine("============= First  Page Loaded ===========");
    }

    private void Page_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
    {
        Console.WriteLine("============= First  Page Context Canchged ===========");
    }
}

Page Loaded screen

image

Application gets stuck at loading

image

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

Build project attached and run it in Windows Apps Sdk target or WASM
Uploading UnoAppNavigation2.zip…

Environment

Nuget Package (s):

Package Version(s):

"Uno.Sdk": "5.4.10"

Affected platform(s):

  • WebAssembly
  • Windows

Visual Studio:

  • 2022 (version: )

Relevant plugins:

Visual Studio 2022
"Uno.Sdk": "5.4.10"

Anything else we need to know?

Activity

  1. added
    kind/bug
    triage/untriaged
    on Nov 8, 2024
  2. erikvilima commented on Nov 15, 2024

    @erikvilima
    Contributor

    @KWodarczyk Thank you for reporting this issue. It seems that the link to the repro app you provided is not working correctly. Could you please check and provide an updated link? Thank you!

  3. KWodarczyk commented on Nov 15, 2024

    @KWodarczyk
    Author

    @eriklimakc hi, not sure if i still have that project but will try to find it, i used "click to add files" and added .zip but not sure why it's not working. I will try to do it again but this can be also reproduces from the pasted code above.

  4. KWodarczyk commented on Nov 15, 2024

    @KWodarczyk
    Author

    UnoAppNavigation2.zip

    @eriklimakc hope this works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugtriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions