Почему я не могу вернуться со страницы входа на страницу регистрации или страницу пароля?
При нажатии кнопки «Назад» ничего не происходит. Не работает ни кнопка возврата устройства (если она доступна), ни строка заголовка или кнопка возврата оболочки.
Это ожидаемая последовательность навигации:
MainPage (introduction slideshow)
|
|-> LoadingPage (authenticate user)
|
|-> LoginPage (not authenticated)
| |
| |-> RegisterPage (can't navigate back)
| |
| |-> PasswordPage (can't navigate back)
|
|
|-> FirstAppPage (authenticated)
MauiProgram.cs
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
...
...
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddSingleton();
AddPage(builder.Services, nameof(MainPage));
AddPage(builder.Services, nameof(LoginPage));
AddPage
(builder.Services, nameof(PasswordPage));
AddPage(builder.Services, nameof(RegisterPage));
}
private static IServiceCollection AddPage(
IServiceCollection services,
string route)
where TPage : Page
where TViewModel : BaseViewModel
{
services
.AddTransient(typeof(TPage))
.AddTransient(typeof(TViewModel));
Routing.RegisterRoute(route, typeof(TPage));
return services;
}
}
AppShell.xaml
AppShell.xaml.cs
public partial class AppShell : Shell
{
public AppShell(AppShellViewModel viewModel)
{
InitializeComponent();
this.BindingContext = viewModel;
}
}
LoginViewModel
public class LoginViewModel : BaseViewModel
{
public Command PasswordCommand { get; }
public Command RegisterCommand { get; }
public LoginViewModel(...)
{
PasswordCommand = new Command(async () => { await Password(); });
RegisterCommand = new Command(async () => { await Register(); });
}
private async Task Password()
{
await Shell.Current.GoToAsync($"{nameof(PasswordPage)}", true);
}
private async Task Register()
{
await Shell.Current.GoToAsync($"{nameof(RegisterPage)}", true);
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... navigation