Hello,
Welcome to our Microsoft Q&A platform!
If the 'Home' route is top level of page A and page B, 'Home' route should be a Tab
instead of a ShellContent
. I create a basic demo about the function, it works as expected. Here is the sample code, you could refer to it.
public class CustomAppShell : Shell
{
public CustomAppShell()
{
Items.Add(new TabBar()
{
Items =
{
new Tab()
{
Title = "Home",
Route = "Home",
Icon = "home.png",
Items =
{
new ShellContent
{
Title = "PageA",
Icon = "pageA",
Route = "PageA",
ContentTemplate = new DataTemplate(typeof(PageA)),
},
new ShellContent
{
Title = "PageB",
Icon = "pageB",
Route = "PageB",
ContentTemplate = new DataTemplate(typeof(PageB)),
},
}
},
new Tab()
{
Title = "SettingPage",
Route = "Setting",
Icon = "setting.png",
Items =
{
new ShellContent
{
ContentTemplate = new DataTemplate(typeof(SettingPage)),
}
}
},
new Tab()
{
Title = "ProgressPage",
Route = "Progress",
Icon = "progress.png",
Items =
{
new ShellContent
{
ContentTemplate = new DataTemplate(typeof(ProgressPage)),
}
}
}
}
});
}
}
Here is the code about navigation:
public partial class PageA : ContentPage
{
public PageA()
{
InitializeComponent();
}
private void NavToProgress_Clicked(object sender, EventArgs e)
{
Shell.Current.GoToAsync("//Progress");
}
private void NavToSetting_Clicked(object sender, EventArgs e)
{
Shell.Current.GoToAsync("//Setting");
}
private void NavToPageB_Clicked(object sender, EventArgs e)
{
Shell.Current.GoToAsync("//Home/PageB");
}
}
Here is the related doc, you could refer to: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#routes
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.