Skip to content

NavigationView disapears on page refresh in WASM #2602

Open

Description

@KWodarczyk

Current behavior

When application loads first time fired form Visual Studio in IIS it all good, but once a refresh button is clicked only "Page One" is shown but whole NavigationView is gone. Also MainPage ctor is not invoked when debugging not sure why.

Screen on first app load

image

Screen after refresh is clicked: (notice how url has changed) from Mian/One to just /One)

image

App.xaml.cs

    //skipped for brevity                
    .UseNavigation(RegisterRoutes)
                );
     MainWindow = builder.Window;
        
    #if DEBUG
            MainWindow.EnableHotReload();
    #endif
            MainWindow.SetWindowIcon();
    
            Host = builder.Build();
    
    
            await builder.NavigateAsync<Shell>();
    }

    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,
                    Nested:
                    [
                        new ("One", View: views.FindByViewModel<FirstViewModel>(),IsDefault:true),
                        new ("Two", View: views.FindByViewModel<SecondViewModel>())
                    ]),
                ]
            )
        );
    }

MainPage.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"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  <Grid uen:Region.Attached="True">

        <NavigationView
            uen:Region.Attached="true"
            PaneDisplayMode="Top"
            IsSettingsVisible="False"
            IsBackButtonVisible="Collapsed"
            IsBackEnabled="False">
            <NavigationView.MenuItems>

                <NavigationViewItem
                  Content="One"
                  x:Name="OneTab"
                  uen:Region.Name="One" />

                <NavigationViewItem
                  Content="Two"
                  x:Name="TwoTab"
                  uen:Region.Name="Two" />


            </NavigationView.MenuItems>

            <NavigationView.FooterMenuItems>

              <NavigationViewItem HorizontalAlignment="Left" Background="DarkSlateGray">
                  <TextBlock>
                    <Run Text="URL:"/>
                    <Run x:Name="UrlPath"/>
                  </TextBlock>
              </NavigationViewItem>

            </NavigationView.FooterMenuItems>

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

MainPage.xaml.cs

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

    public MainViewModel ViewModel { get; set; }

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

        this.InitializeComponent();

        UrlPath.Text = _app.MainHref;
    }
}

Expected behavior

I expect application to look exactly the same after refresh as before refresh.

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

Just build the attached solution for wasm and run it in Visual Studio in debug mode.
After application loads in the browser, refresh page
UnoAppNavigation2.zip

Workaround

There is a workaround but it's not ideal since both pages load as soon as application loads even though only the fist page is set to Visible:

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)
                ]
            )
        );
    }

MainPage.xaml

            uen:Region.Attached="true"
            PaneDisplayMode="Top"
            IsSettingsVisible="False"
            IsBackButtonVisible="Collapsed"
            IsBackEnabled="False">
            <NavigationView.MenuItems>

                <NavigationViewItem
                  Content="One"
                  x:Name="OneTab"
                  IsSelected="True"
                  uen:Region.Name="One" />

                <NavigationViewItem
                  Content="Two"
                  x:Name="TwoTab"
                  uen:Region.Name="Two" />


            </NavigationView.MenuItems>

            <NavigationView.FooterMenuItems>

              <NavigationViewItem HorizontalAlignment="Left" Background="DarkSlateGray">
                  <TextBlock>
                    <Run Text="URL:"/>
                    <Run x:Name="UrlPath"/>
                  </TextBlock>
              </NavigationViewItem>

            </NavigationView.FooterMenuItems>

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

              <!--thsi will work but both pages are loaded as soon as app load, not ideal-->
              <Presentation:FirstPage Visibility="Collapsed" uen:Region.Name="One"/>
              <Presentation:SecondPage Visibility="Collapsed" uen:Region.Name="Two"/>

            </Grid>
        </NavigationView>

Works on UWP/WinUI

None

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

"Uno.Sdk": "5.4.10"

Affected platforms

WebAssembly

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    kind/bug
    triage/untriaged
    on Nov 5, 2024
  2. jeromelaban commented on Nov 5, 2024

    @jeromelaban
    Member

    Thanks for the report. Can you specify what you mean by "refresh"?

  3. added
    triage/needs-information
    on Nov 5, 2024
  4. KWodarczyk commented on Nov 5, 2024

    @KWodarczyk
    Author

    sure,
    image

  5. removed
    triage/needs-information
    on Nov 5, 2024
  6. jeromelaban commented on Nov 5, 2024

    @jeromelaban
    Member

    Thanks, this helps. This looks like an Extensions Navigation issue related to deep linking.

    /cc @kazo0 @nickrandolph

  7. transferred this issue fromunoplatform/unoon Nov 5, 2024
  8. erikvilima commented on Nov 5, 2024

    @erikvilima
    Contributor

    Same as #2488

    cc @kazo0

  9. DevTKSS commented on Jan 1, 2025

    @DevTKSS
    Contributor

    Content of NavigationView is also disapearing on HotReload (Dektop Target) when using x:Bind => maybe Related to this reload because the VM is exchanged?

  10. added theissue type on Jun 20, 2025
  11. DevTKSS commented on Oct 15, 2025

    @DevTKSS
    Contributor

    @Kunal22shah would you check if that issue is the same source than the blank page resulting navigation you issued some days ago?

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