question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Nested route doesn't work after history.goBack()

See original GitHub issue

Bug 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:

  1. Make an app with nested routes.
  2. Push a page
  3. Pop the page with history.goBack()
  4. 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:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
elylucascommented, Oct 21, 2019

Hi @puku0x,

Thanks for the issue, this should be fixed in the upcoming 4.11.2 release which should be out today.

0reactions
ionitron-bot[bot]commented, Nov 20, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found