admin管理员组

文章数量:1389903

I am using C# Maui with the .NET 9.0 SDK.

Using routes registered using Routing.RegisterRoute and navigating between views using Shell.Current.GoToAsync seems to result in some odd shell states.

For example, after registering the following views:

Routing.RegisterRoute("login", typeof(LoginPage));
Routing.RegisterRoute("profile", typeof(ProfilePage));
Routing.RegisterRoute("history", typeof(HistoryPage));

If a user navigates from login to profile to history and back to profile, eventually the app's shell state resembles the following:

////login/profile/history/profile

When the app reaches this state, attempting to navigate from profile to history a second time produces the error in the method SearchForGlobalRoutes of the ShellUriHandler object.:

Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

Similarly, in the same scenario attempting to navigate backwards using the .. notation results in an error that the route could not be discovered.

Has anyone else had this sort of experience? Is there something I am missing in either the registration or navigation of my routes?

Edit

I should mention that navigating away from the startup view using an absolute path such as the following seems to result in the app hanging / becoming non-responsive:

Shell.Current.GoToAsync("//profile")

Navigating using either of the following does not suspend the app, but results in the odd state shown above:

Shell.Current.GoToAsync("profile")
Shell.Current.GoToAsync("/profile")

Edit

At the time of posting, all routes were registered in the CreateMauiApp method of the MauiProgram class.

Since posting, I have also tried registering routes in the constructor of the AppShell class, but have had no significant change in behavior.

public partial class AppShell : Shell
{
    public AppShell()
    {
        InitializeComponent();

        RegisterRoutes();
    }

    private void RegisterRoutes() {
        Routing.RegisterRoute("profile", typeof(ProfilePage));
        Routing.RegisterRoute("history", typeof(CallHistoryPage));
        Routing.RegisterRoute("settings", typeof(SettingsPage));

    }
}

本文标签: cNavigating back and forth between views creates odd states in NET MauiStack Overflow