Skip to content

IRouteNotifier + NavigationView + MVUX + Navigator not reliable? #2663

Description

@DevTKSS

Current behavior

Listening to RouteNotifier as described in uno docs from MainModel as corresponding Model to MainPage where the apps NavigationView is placed, the output is case 1 empty string or case 2 "Tab" indicating the TabNavigationBar ib the bottom of this app, but never showing any of the route names in Route registry or xaml named regions.

Expected behavior

If that output would be the current route as expected it would maybe be possible to set the NavigationView Header Content to that Page Title=Route to not havong to add a header definition to each of them

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

  1. Create a app using mvux, regions, DI with recommended template
  2. Set app.xaml.cs Route Registry:
    ViewMap s for at least 3 pages incl. Their models, so add one
  3. RouteMap:
    Main is nested to shell, second and third page nested to main, second to be default, same as main.
  4. Clear each pages current content
  5. Add NavigationView to MainPage, incl Region.Attached = true
  6. Add at least two menuitems NavigationViewItem s and add Region.Name to each of them to show the correct selection corresponding to shown content
  7. On the NavigationView properties place CommandExtensions.Command bound to MainModel to cantral navigation handler
  8. If you like to get some "Tab" output, add a TabNavigationBar with named Regions
  9. Add some simple content to the second and third page like a textblock with its name
  10. Install the IRouteNotifier exactly as told in documentation
  11. on route change let it set this text to MainModel IState<string>CurrentHeaderText
  12. bind this to the NavigationView.Header

Start and check it out. No header will be there

Environment

Nuget Package (s):

Package Version(s):

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: latest)
  • Visual Studio Code (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

Would be nice to be able to set the NavigationView.Header to the current pages header or similar to not have to set this up at each page individually. On wpf or similar pages do have Title property to fill this in, on uno that is at least not available on intellisense...

Activity

  1. added
    kind/bug
    triage/untriaged
    on Jan 13, 2025
  2. DevTKSS commented on Mar 4, 2025

    @DevTKSS
    ContributorAuthor

    Inspected the playground solution in this repo where this Interface is sampled. Will check its compatibility with a non shellmodel and check why that code in the docs is not working as expected

  3. DevTKSS commented on May 15, 2025

    @DevTKSS
    ContributorAuthor

    To get the actual Route by IRouteNotifier.RouteChanged(object? sender, RouteChangedEventArgs args) the Event Property of Type IRegion.Name is not usable as shown in the Docs.

    After inspecting the src I would recommend to change IRegion Property to Route in general since that seems to be the meant task for this property? @MartinZikmund

    @agneszitte For the docs to get the expected result of the How-To use IRouteNotifier to Monitor Changes, we need to set it up like this e.g. in mvux:

    public partial record MainModel
    {
        private readonly INavigator _navigator;
        private readonly IRouteNotifier _routeNotifier;
        public MainModel(
            INavigator navigator,
            IRouteNotifier routeNotifier)
        {
            _routeNotifier = routeNotifier;
            _navigator = navigator;
            _routeNotifier.RouteChanged += (s,routeArgs) =>
            {
                this.CurrentNotifierRoute.SetAsync(routeArgs.Navigator?.Route?.ToString() ?? string.Empty); // actual current nested route
                this.CurrentNotifyerRegion.SetAsync(routeArgs.Region?.Name); // no return from this
            };
        }
    
        public IState<string> CurrentNotifyerRegion => State<string>.Value(this, () => _navigator.Route?.ToString() ?? string.Empty);
        public IState<string> CurrentNotifierRoute => State<string>.Value(this,() => string.Empty);

    Page content used:

    <TextBlock Grid.Row="1"
               Grid.Column="0"
               HorizontalTextAlignment="Right"
               Text="Notifier Region:" />
    <TextBlock Grid.Row="1" Grid.Column="1"
               Text="{Binding Path=CurrentNotifierRegion, Mode=OneWay}" />
    <TextBlock Grid.Row="2"
               Grid.Column="0"
               HorizontalTextAlignment="Right"
               Text="Notifier Route:" />
    <TextBlock Grid.Row="2" Grid.Column="1"
               Text="{Binding Path=CurrentNotifierRoute, Mode=OneWay}" />

    Visual Result from this implementation, which would be the actual expected Result in my opinion:

    Image

    PS: you see the NavigationView Content initially empty, because I used HotReload to update the App. Filed this as Issue that navigator seems to have problems on having the nested Region Content again after Reloading, @nickrandolph told me there:

    This will be a limitation of navigation for the initial release of HD due to the need to maintain more complex state. If you use pages for the content inside the navigationview, only the page content should be updated, without reloading the entire page

    (??? since when is HotReload equal to HotDesign? just filed it there because I have been told HotReload and HotDesign are now both parts of "Studio")

    maybe he missed my reply there, but in my understanding HotReload is defintly not in initial Release at all and to me the Navigator should be able to let us update the parented page and again insert the correct Region content while reloading.
    Maybe this issue can get inspected again

    @agneszitte let me know if you want to get the docs updated for IRouteNotifyer

  4. DevTKSS commented on May 19, 2025

    @DevTKSS
    ContributorAuthor

    Maybe this other issue could get resolved by the mentioned comlication also:

    #2606

    When I defined the eventhandler in line with using lambda instead of seperate function, which could get made async, I can agree that did not update the state it was requested to update!

  5. added theissue type on Jun 20, 2025
  6. kazo0 commented on Jun 25, 2025

    @kazo0
    Contributor

    @DevTKSS sorry trying to follow up on this, is the issue here that the IRouteNotifier EventArgs are not being set properly or simply that we should update the docs to show it using routeArgs.Navigator?.Route instead of routeArgs.Region?.Name?

  7. DevTKSS commented on Jun 25, 2025

    @DevTKSS
    ContributorAuthor

    @kazo0

    minimal:

    updating the docs to tell us the working way for this, because the shown approach is not working for the result we are told to use it for

    Better:

    If the event arguments are useful for something else, please add this information additionally.


    I don't know if the Route changed Event arguments should do this expected and that Region object not beeing useful for something else I don't know, then its up to you/Uno to take future steps 🤷

  8. DevTKSS commented on Jun 26, 2025

    @DevTKSS
    ContributorAuthor

    This linked would also add the appropriate xml comments we currently dont have for the Route.ToString() overwrite to improve that In our IDE

  9. DevTKSS commented on Aug 21, 2025

    @DevTKSS
    ContributorAuthor

    not in the docs but showed in my tutorial the How To to this 👍

    https://youtu.be/RZ3RirA7jhk

    @jeromelaban not sure if this makes it now state of "Fixed"? 😅 I mean for non German People its not correct in the docs 🤔 I could send a PR beginning of next month to update the docs, but I am not sure whats the reason, that we are until now are told to use the not-working approach. maybe this works only if its in App.xaml.cs or Shell but not on e.g. MainModel?
    not sure...

  10. linked a pull request that will close this issuefix: adjust routenotifier logic #3028on Feb 17, 2026
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions