38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
namespace MauiApp.Core.System.Navigation;
|
|
|
|
public class NavigationService : INavigationService
|
|
{
|
|
|
|
private readonly AppShell appShell;
|
|
|
|
private const string HomePage = nameof(MainPage);
|
|
|
|
|
|
public NavigationService(AppShell appShell)
|
|
{
|
|
this.appShell = appShell;
|
|
}
|
|
|
|
public async Task NavigateAsync(string pageName, INavigationParameters pageParams = null, bool clearStack = false)
|
|
{
|
|
pageParams ??= new NavigationParameters();
|
|
await appShell.GoToAsync((clearStack ? "//" : "") + pageName, true, pageParams);
|
|
}
|
|
|
|
public async Task NavigateAsync<TPage>(INavigationParameters pageParams = null, bool clearStack = false) where TPage : Page
|
|
{
|
|
var pageName = typeof(TPage).Name;
|
|
await NavigateAsync(pageName, pageParams, clearStack);
|
|
}
|
|
|
|
public async Task GoBackAsync()
|
|
{
|
|
await appShell.Navigation.PopAsync(true);
|
|
}
|
|
|
|
public async Task GoToRootAsync()
|
|
{
|
|
//await appShell.Navigation.PopToRootAsync(true);
|
|
await appShell.GoToAsync($"//{HomePage}");
|
|
}
|
|
} |