How to open same page as nested with Shell Flyout?

Pelin Konaray 291 Reputation points
2022-07-18T12:24:07.98+00:00

I worked at xamarin forms for a long time. I have an app running on xamarin forms thats published to the market currently. I'm doing preliminary work to migrate this app to maui. But I have some problems.

I have a page template and when I press a button in this template, another page in the same template opens again. (For example, I have an application such as google drive. There is a listview in the page. The names of the folders and files are listed in this listview. If I press the folder name in the list, I want to show the new folders and files in the new page. So the template of the page is the same, but the pages different.)
For this, I am having trouble navigating with shell.

I created very simple project for now. It only has AppShell.xaml and MainPage.xaml. I registered the MainPage in AppShell.xaml.cs. (MainPage is ContentTemplate in the AppShell.xaml).
I added a button to MainPage that called "GoNextPage" and if clicked the button, it tries to open the same page again. (with the command "await Shell.Current.GoToAsync(nameof(MainPage));")

But when I try to do this I get an error like this:
"System.Exception: 'Relative routing to shell elements is currently not supported. Try prefixing your uri with / //:///MainPage'"

How can I solve this?
I added sample project in the following link:
https://drive.google.com/file/d/1nHPLiag8Y-JDbdHMweDQw2bXNeucaUBH/view?usp=sharing

Thanks in advance.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,927 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,751 Reputation points Microsoft Vendor
    2022-07-19T06:16:10.757+00:00

    Hello @Pelin Konaray ,

    As described in .NET MAUI Shell navigation - .NET MAUI | Microsoft Learn, the routes in an app should be unique. You have set the route in ShellContent :

    <ShellContent  
            Title="Home"  
            ContentTemplate="{DataTemplate local:MainPage}"  
            Route="MainPage" />  
    

    And you set the route again in AppShell.xaml.cs , you could try to set a different route:

     Routing.RegisterRoute("SecondMainPage", typeof(MainPage));// the different rout as you said" the template of the page is the same, but the pages different"  
     //  Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));  
    

    Then you can go to the next page :

     await Shell.Current.GoToAsync("SecondMainPage");  
    

    Another way to achieve this, you don't have to register routes, try to find the navigation, then push a new page

    await Shell.Current.Navigation.PushAsync(new MainPage());  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful