ionic-framework
ionic-framework copied to clipboard
bug: vue and react routing integrations always pop when forward button is pressed
Bug Report
Ionic version:
[ ] 4.x [x] 5.x
Current behavior:
If I press back button and press forward button the url is correct but the page is wrong
Expected behavior:
it should display correct page
Steps to reproduce:
Related code:
App component
const App: React.FC = () => (
<IonApp>
<IonReactRouter>
<IonRouterOutlet>
<Route exact path='/pageone' component={PageOne}/>
<Route exact path='/pagetwo' component={PageTwo}/>
<Route exact path='/pagethree' component={PageThree}/>
<Route exact path='/pagefour' component={PageFour}/>
<Redirect exact from={'/'} to={'/pageone'}/>
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
);
PageOne component
const PageOne = ({ history }) => {
return (
<IonPage>
<IonContent fullscreen>
<p>This is Page One!</p>
<IonButton onClick={() => history.push('/pagetwo')}>
Go to page two
</IonButton>
</IonContent>
</IonPage>
)
}
PageTwo component
const PageTwo = ({ history }) => {
return (
<IonPage>
<IonContent fullscreen>
<p>This is Page Two!</p>
<IonButton onClick={() => history.push('/pagethree')}>
Go to page three
</IonButton>
</IonContent>
</IonPage>
)
}
Other information:
Example:
https://www.loom.com/share/048952f5848f443a8e108f52906e0ba4
Question:
- Based on the Ionic component doc, we need to use
href
inIonButton
in order to go to a page which does not render page transition animation (I assume it just updates the location.href). But I can also userouterLink
to go to a page with page transition. Which is recommended?
Thanks for the issue. Can you reproduce this in an Ionic starter app and provide a link to the repo?
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.
Thanks for the issue. Can you reproduce this in an Ionic starter app and provide a link to the repo?
https://github.com/uwwangxiangyu/ionic-routing-issue
Thanks for the follow up. Can you please provide some steps to reproduce the issue? I cannot reproduce this issue on my end.
Thanks for the follow up. Can you please provide some steps to reproduce the issue? I cannot reproduce this issue on my end.
- Go to root ip
- Press button to page2
- Press button to page3
- Press button to page4
- Press back button of the browser
- Press forward button of the browser
On my end I can see the url is correct but the page is wrong https://www.loom.com/share/048952f5848f443a8e108f52906e0ba4?t=0
Thanks. The problem here seems to be that when the forward button is pressed in the browser, the onpopstate
event is fired even though we want to push a page not pop it. I need to do some digging to see if there's any way we can account for this.
This also impacts Ionic Vue ~and probably impacts Ionic Angular~. One idea as to how we could fix this is to compare the location that the router has directed us to with the pathname of the previous item in our locationHistory
stack. If the current path does not equal the previous path, then this we actually want to push an item to the stack.
Some pseudo code:
handleHistoryChange(location, action) {
...
let realAction = action;
if (action === 'pop') {
const previous = locationHistory.previous();
const current = locationHistory.current();
// If path we are on does not equal the previous
// location item's path, then we might not actually
// want to pop off the stack.
if (location.path !== previous.pathname) {
realAction = 'push';
}
}
}
Not sure how this would work in practice, but I can test it out.
Not sure how this would work in practice, but I can test it out.
@liamdebeasi I see you've already looked into this issue. What did you find? What are the outlooks for this issue?
@liamdebeasi are there any updates or comments on this issue?
I don't have any updates on the issue. Someone from the team will post here when we do.
@liamdebeasi Is there any known workaround for this issue?