auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

Issues combining pop with back, creating a loop.

Open kane-knowby opened this issue 1 year ago • 3 comments

Scenario:

You are on RouteA. router.navigate(RouteB); router.navigate(RouteC); (From RouteB) router.pop(); (From RouteC) router.back(); (From RouteB)

Expected result: RouteA Actual result: RouteC

You might say, that is fine, just use .back() everywhere instead of .pop().

Problem is that on iOS native swipe back and android physical back button, the app will use .pop();

The other problem is that someone can forget to use back one time, and the pop will cause crazy looping behaviour.

The way to fix this (in my opinion):

  • For iOS/Android, when the navigation history detects new urlState, if the previous entry in the history is equal to the new url state, simply remove the entry from the history instead of adding.
  • For web, because can't access the browser history, change the pop method to use back instead (If on web and not returning a result).

I've made these fixes in my fork and is working beautifully, I will create a PR.

kane-knowby avatar Jan 18 '24 03:01 kane-knowby

maybe you need check context.mouted before pop

oengmengthong avatar Jan 19 '24 04:01 oengmengthong

maybe you need check context.mouted before pop

The issue stems from how auto_route uses NavigationHistory to facilitate back().

When you call .pop(), the navigation history doesn't remove the popped page from the history, so when you call .back() next, it thinks the page you already popped is the previous page.

kane-knowby avatar Jan 20 '24 01:01 kane-knowby

@Milad-Akarie Has this been looked at yet?

k-ane avatar Mar 29 '24 09:03 k-ane