How to clear navigation stack in App Shell

RK 0 Reputation points
2023-08-16T09:51:46.6+00:00

I'm currently using the App Shell in my application. I would like to clear the previously opened pages in my app. How to clear the previously opened pages in MAUI App Shell?

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

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 79,311 Reputation points Microsoft Vendor
    2023-08-17T03:04:03.3933333+00:00

    Hello,

    How to clear the previously opened pages in MAUI App Shell?

    You can get the Shell's Navigation stack, then remove all of them one by one like following code.

    var stack = Shell.Current.Navigation.NavigationStack.ToArray();
    for(int i = stack.Length - 1; i > 0; i--)
    {
       Shell.Current.Navigation.RemovePage(stack[i]);
    }
    

    Best Regards,

    Leon Lu


    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.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.