ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

bug: react, router.go does not show correct view when n < -1

Open liamdebeasi opened this issue 3 years ago • 7 comments

Prequisites

Ionic Framework Version

  • [ ] v4.x
  • [X] v5.x
  • [ ] v6.x

Current Behavior

Navigating using router.go(n) with an n value less than -1, Ionic React does not show the correct view because it always assumes a delta of 1 or -1.

Expected Behavior

I would expect Ionic React to show the correct view regardless of the delta value.

Steps to Reproduce

  1. Start with one page and push 2 IonPages to navigation stack via navigation.push()
  2. Let the 3rd page navigate back ("history stack pop") to the first page via navigation.go(-2)
  3. Observe that react's router does produce the proper URL (path) of the first page. But also observe that the the previous route (page) in the history stack is rendered, not the very first page which belongs to that path.

Code Reproduction URL

https://github.com/larsblumberg/ionic-back-navigation-broken

Ionic Info

No response

Additional Information

This is a continuation of https://github.com/ionic-team/ionic-framework/issues/22563.

At the time of writing, there does not seem to be a straightforward way to implement this. The fix for this in Ionic Vue relied on Vue Router exposing a delta value as well as a custom state object in window.history.state that let us track which view to show. React Router does not expose this kind of information according to https://github.com/remix-run/history/issues/36#issuecomment-233652964 and https://github.com/remix-run/history/issues/334#issuecomment-244250026.

One option is we could build this position tracking into Ionic React ourselves, but I am a bit hesitant to start altering window.history.state especially when React Router already manages the state for us.

liamdebeasi avatar Aug 17 '21 12:08 liamdebeasi

I think this issue is also related - https://codesandbox.io/s/wild-cloud-933jc?file=/src/App.js Using history(or router).goBack() more than one time doesn't work (slightly modified example than the one linked in the original issue) Please note the comments on the 3rd page - When running on iOS / (Safari on macOS) (be it through safari or in a real app) no matter how many calls to .goBack(), it always goes back 1 page (URL also goes back 1 page) On web and android it seems to sometimes work (can't reproduce when, but after changing between all instances of history / router It seems to not go back any amount of pages (but still updates the URL))

What would be a temporary workaround on iOS / Safari? In our app it seems to work fine on android and web(chrome), running the latest stable versions of ionic-react

fr3fou avatar Aug 17 '21 19:08 fr3fou

I think this issue is also related - https://codesandbox.io/s/wild-cloud-933jc?file=/src/App.js Using history(or router).goBack() more than one time doesn't work (slightly modified example than the one linked in the original issue) Please note the comments on the 3rd page - When running on iOS / (Safari on macOS) (be it through safari or in a real app) no matter how many calls to .goBack(), it always goes back 1 page (URL also goes back 1 page) On web and android it seems to sometimes work (can't reproduce when, but after changing between all instances of history / router It seems to not go back any amount of pages (but still updates the URL))

What would be a temporary workaround on iOS / Safari? In our app it seems to work fine on android and web(chrome), running the latest stable versions of ionic-react

is there are workaround for this? this is a huge blocker for me

lyubchev avatar Aug 21 '21 12:08 lyubchev

Is there a workaround for this? How can one return multiple pages back in the history stack? Looks like Ionic 6 RC for React has the same issue.

kazlauskis avatar Oct 18 '21 12:10 kazlauskis

Same issue with Vue.

However calling router.back() twice does work.

lschmierer avatar Feb 08 '22 13:02 lschmierer

It's actual for our team.

I think this issue is also related - https://codesandbox.io/s/wild-cloud-933jc?file=/src/App.js Using history(or router).goBack() more than one time doesn't work (slightly modified example than the one linked in the original issue) Please note the comments on the 3rd page - When running on iOS / (Safari on macOS) (be it through safari or in a real app) no matter how many calls to .goBack(), it always goes back 1 page (URL also goes back 1 page) On web and android it seems to sometimes work (can't reproduce when, but after changing between all instances of history / router It seems to not go back any amount of pages (but still updates the URL))

What would be a temporary workaround on iOS / Safari? In our app it seems to work fine on android and web(chrome), running the latest stable versions of ionic-react

Do you have any solution for this? @liamdebeasi @sean-perkins

ashish-yourphysio avatar Apr 20 '23 10:04 ashish-yourphysio

Is there any solution or workaround? How can we return back multiple pages?

panatchakorn-tw avatar Nov 22 '23 02:11 panatchakorn-tw