Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: React navigation back and history.goBack() #29130

Closed
3 tasks done
FernetB opened this issue Mar 8, 2024 · 5 comments
Closed
3 tasks done

bug: React navigation back and history.goBack() #29130

FernetB opened this issue Mar 8, 2024 · 5 comments
Assignees
Labels
ionitron: needs reproduction a code reproduction is needed from the issue author

Comments

@FernetB
Copy link

FernetB commented Mar 8, 2024

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Hello!

Right know if u:
go from HOME-> A -> B -> C
then from C do navigation("/B", "back", "pop")
then from B do navigation("/A", "back", "pop")
the from A do history.goBack() A goes to B instead of HOME

I know that u would ask why are u doing that? but i have a custom goBack that uses the pushedByRoute from the routeInfo in the useIonRouter
something like this:

  const { routeInfo, push } = useIonRouter();
  const history = useHistory();

  const routePushed = useRef<string | undefined>(routeInfo.pushedByRoute);

  const goBack = useCallback(
    (path?: string) => {
      if (path) {
        push(path, "back", "pop");
      } else {
        if (routePushed.current) {
          push(routePushed.current, "back", "pop");
        } else {
          history.goBack();
        }
      }
    },
    [history, push]
  );

But clarly push(routePushed.current, "back", "pop"); does not behave like an history.goBack() in terms of history stack

it would be nice if it is explained a litle bit more what does really do "pop" and also in other hand, what is the main difference between history.goBack() and goBack() from useIonRouter that in the docs only says
image
but not fully explains what "Navigates backwards in history, using the IonRouter to determine history" means

EDIT: I fount that either push and navigates always push the next route into the stack, and pop only pops the current path from the stack

Expected Behavior

I dont know if it is the expected behavior, but someone would think that push(/route, "back", "pop"); or navigate(/route, "back", "pop"); (if used from NavContext) will behave like a history.goBack()

Steps to Reproduce

Is explained before

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 7.1.1
Ionic Framework : @ionic/react 7.7.4

Capacitor:

Capacitor CLI : 5.2.3
@capacitor/android : 5.2.3
@capacitor/core : 5.2.3
@capacitor/ios : 5.2.3

Utility:

cordova-res : 0.15.1
native-run : 1.7.2

System:

NodeJS : v18.16.0
npm : 9.5.1
OS : Windows 10

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Mar 8, 2024
@liamdebeasi liamdebeasi added the ionitron: needs reproduction a code reproduction is needed from the issue author label Mar 8, 2024
Copy link

ionitron-bot bot commented Mar 8, 2024

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

@ionitron-bot ionitron-bot bot removed the triage label Mar 8, 2024
@FernetB
Copy link
Author

FernetB commented Mar 11, 2024

I don't think it need reproduction because clearly push and navigate adds one history entry intro the stack, but the docs of this and the goBack from ionRouter is poorly.
Could someone explain what is the meaning of the goBack using the IonRouter to determinate history? And what is the diference with history.goBack()

@liamdebeasi
Copy link
Contributor

We ask for a reproduction so we can be sure that we are verifying the same issue that you are reporting. Routing issues can be sometimes complex to debug, so a reproduction is very helpful here too.

@thetaPC
Copy link
Contributor

thetaPC commented Mar 22, 2024

This issue is being closed due to lack of a reproduction. If this is still a problem in the latest version of Ionic, please open a new issue and ensure the template is fully filled out. Thank you!

@thetaPC thetaPC closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
Copy link

ionitron-bot bot commented Apr 21, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ionitron: needs reproduction a code reproduction is needed from the issue author
Projects
None yet
Development

No branches or pull requests

3 participants