Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping pages in xamarin forms in Back Navigation

Four page xamarin forms, pages 1>2>3>4 with page 4 as the last page to navigate to

After Navigating to page 4, i want to go back to page 2, skipping page 3

I tried putting a button on page 4 that navigates back to page 2

But after clicking the Back button, it brings me back to page 4 instead of page 1

im stuck

like image 441
John Carlo Ol'CAt Lacadin Avatar asked Oct 24 '25 02:10

John Carlo Ol'CAt Lacadin


1 Answers

Now that you have 4 pages in your navigation stack 1>2>3>4 and now you want to go from Page 4 to Page 2. You have to remove Page 3, You can not navigate to Page 2 Because then the stack will become this 1>2>3>4>2. You want the stack to be like 1>2>4 .So when you pop from Page 4 it goes to Page 2.

Code to remove Page 3 from stack

var page = Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]; 
// you have the second last page now in page variable
Navigation.RemovePage(page);

after this stack will become 1>2>4 Now, you can write following in page 4

await Navigation.PopAsync();

And you'll come to page 2.

like image 139
Shubham Tyagi Avatar answered Oct 25 '25 16:10

Shubham Tyagi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!