ionic-team / ionic-team/ionic-framework
bug: react, router.go does not show correct view when n < -1
- Lingua principale
- TypeScript
- Stelle
- 52.7k
- Fork
- 13.3k
- Merge medio
- 1g 15h
- PR unite (30g)
- 51
Descrizione
### Prequisites
- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.
### 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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start with the linked reproduction and the React router.go navigation path, focusing on navigation.go(-2) after two pages have been pushed. Compare the URL with the rendered view when n is less than -1, and review the prior issue #22563 for context. Done means Ionic React renders the page matching the destination history entry for larger negative deltas.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react, typescript
- Ambito
- frontend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100