bug: Nested route doesn't work after history.goBack()
See original GitHub issueBug Report
Ionic version:
[x] 4.11.1
Current behavior:
A blank page is shown when pushing a page after popping a page by using history.goBack()
when routes are nested with IonRouterOutlet
.
*It worked well with IonBackButton
, though.
Expected behavior:
It should show a page.
Steps to reproduce:
- Make an app with nested routes.
- Push a page
- Pop the page with
history.goBack()
- Push the page again Then, a blank page will be shown.
Related code: https://codesandbox.io/s/ionicreact-nested-route-sample-5n5dg
const App: React.FunctionComponent = () => {
return (
<IonApp>
<IonReactRouter>
<IonRouterOutlet>
<Route exact path="/login" component={LoginPage} />
<Route path="/" component={MainPage} />
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
);
};
export const MainPage: React.FunctionComponent = () => {
return (
<IonRouterOutlet>
<Route exact path="/" render={() => <Redirect to="/users" />} />
<Route exact path="/users" component={UserListPage} />
<Route exact path="/users/:id" component={UserDetailPage} />
</IonRouterOutlet>
);
};
export const UserListPage: React.FunctionComponent = () => {
return (
<IonPage>
<IonHeader>
<IonToolbar color="primary">
<IonButtons slot="start">
<IonMenuButton />
</IonButtons>
<IonTitle>UserListPage</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonList>
<IonItem routerLink="/users/1">
<IonLabel>User 1</IonLabel>
</IonItem>
<IonItem href="/users/2">
<IonLabel>User 2</IonLabel>
</IonItem>
<IonItem href="/users/3">
<IonLabel>User 3</IonLabel>
</IonItem>
</IonList>
</IonContent>
</IonPage>
);
};
export const UserDetailPage: React.FunctionComponent = () => {
const history = useHistory();
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonButtons slot="start">
<IonBackButton defaultHref="/users" />
</IonButtons>
<IonTitle>UserDetailPage</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonButton expand="full" onClick={() => history.goBack()}>
Back
</IonButton>
</IonContent>
</IonPage>
);
};
Other information:
😭Ionic React conference app doesn’t help me because it uses the outdated @ionic/react
Ionic info:
Ionic:
Ionic CLI : 5.4.4
Utility:
cordova-res : not installed
native-run : not installed
System:
NodeJS : v10.16.3
npm : 6.9.0
OS : macOS Mojave
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
bug: Nested route doesn't work after history.goBack() #19701
A blank page is shown when pushing a page after popping a page by using history.goBack() when routes are nested with IonRouterOutlet ....
Read more >Nested Routing Not Working in React Router v6 - Stack Overflow
First, fix the invariant warning for the nested route you are trying to match. You rendered descendant `<Routes>` (or called `useRoutes()`) ...
Read more >[Solved]-React Router history.goBack doesn't work when ...
Coding example for the question React Router history.goBack doesn't work when using -Reactjs.
Read more >Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >Upgrading from v5 v6.6.1 - React Router
Then you can come back later and pick up where you left off. ... In large apps, you can still nest routes in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @puku0x,
Thanks for the issue, this should be fixed in the upcoming 4.11.2 release which should be out today.
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.