auto_route_library
auto_route_library copied to clipboard
Issues combining pop with back, creating a loop.
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.
maybe you need check context.mouted before pop
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.
@Milad-Akarie Has this been looked at yet?