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: IonRouterOutlet does not handle recursive routes/paths #23051

Closed
cdes opened this issue Mar 16, 2021 · 11 comments
Closed

bug: IonRouterOutlet does not handle recursive routes/paths #23051

cdes opened this issue Mar 16, 2021 · 11 comments
Labels

Comments

@cdes
Copy link
Contributor

cdes commented Mar 16, 2021

Bug Report

Ionic version:

[ ] 4.x
[x] 5.6.0

Current behavior:

Consider a page component that shows a user profile and a list of friends.
When tapping on a friend, the app navigates to a new route to display that friend's profile along with a list of friends using the same page component. In other words, recursive routing.

CleanShot 2021-03-16 at 04 51 21

Expected behavior:

Ionic navigation should keep showing the screen and building the url as you go deeper in the recursive path.

I've used this as a guide:
https://reactrouter.com/web/example/recursive-paths

Steps to reproduce:

Related code:

A sample application via code sandbox
https://codesandbox.io/s/ionic-recursive-route-x9r8x?file=/src/app.tsx

Other information:

Ionic info:

Versions

"@ionic/react": "5.6.0",
"@ionic/react-router": "5.6.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-router-dom": "5.2.0",
@ionitron-bot ionitron-bot bot added the triage label Mar 16, 2021
@liamdebeasi
Copy link
Contributor

Thanks for the issue. In the react-router example you provided, the example author adds the following code which is necessary for this functionality to work:

<Route path={`${url}/:id`}>
  <Person />
</Route>

This code was not found in your CodeSandbox, and adding it seems to make it work. Can you give that a shot?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Mar 16, 2021
@ionitron-bot ionitron-bot bot removed the triage label Mar 16, 2021
@cdes
Copy link
Contributor Author

cdes commented Mar 17, 2021

@liamdebeasi Unfortunately no. I've tried that before and nothing appears, which means that the route was not matched.

I've also updated the code sandbox code.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Mar 17, 2021
@liamdebeasi
Copy link
Contributor

Hmm, I am not sure that usage is correct. Your example wraps the component template in a Route component, but the example on the react-router docs places the Route component inside of the template.

I would recommend placing the Route inside of the template as that was what worked for me. So your code would look something like this:

<IonPage>
  <IonHeader collapse="condense">
    <IonToolbar>
      <IonButtons slot="start">
        <IonBackButton />
      </IonButtons>
      <IonTitle>Friends App</IonTitle>
    </IonToolbar>
  </IonHeader>
  <IonContent>
    <div
      style={{
        display: "flex",
        alignItems: "center",
        padding: 16
      }}
    >
      <IonAvatar
        style={{
          width: 64,
          height: 64
        }}
        slot="start"
      >
        <img src={person?.avatar} />
      </IonAvatar>
      <IonText
        style={{
          marginLeft: 16,
          fontSize: 32
        }}
      >
        {person.name}
      </IonText>
    </div>
    <IonList>
      <IonListHeader
        style={{
          fontSize: 16,
          textTransform: "uppercase"
        }}
      >
        Friends
      </IonListHeader>
      {person.friends.map((id) => (
        <IonItem
          key={id}
          routerLink={`${url}/${id}`}
          routerDirection="forward"
        >
          <IonLabel>{find(id).name}</IonLabel>
        </IonItem>
      ))}
    </IonList>
  </IonContent>

  <Route path={`${url}/:id`}>
    <User />
  </Route>

</IonPage>

Note the Route immediately before the closing IonPage tag.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Mar 17, 2021
@ionitron-bot ionitron-bot bot removed the triage label Mar 17, 2021
@cdes
Copy link
Contributor Author

cdes commented Mar 17, 2021

Interesting... navigation works but the transitions are not

CleanShot 2021-03-17 at 19 26 41

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Mar 17, 2021
@cdes
Copy link
Contributor Author

cdes commented Mar 17, 2021

I've managed to create another example for recursive route. The transition works, but this has a different issue.

The back button only goes back ones and then disappears.

https://codesandbox.io/s/ionic-recursive-route-forked-9u5ot?file=/src/app.tsx

CleanShot 2021-03-17 at 19 52 32

@JayBizzle
Copy link

Just as a side note, i think this issue is related to #22662

@liamdebeasi
Copy link
Contributor

I've managed to create another example for recursive route. The transition works, but this has a different issue.

The back button only goes back ones and then disappears.

https://codesandbox.io/s/ionic-recursive-route-forked-9u5ot?file=/src/app.tsx

CleanShot 2021-03-17 at 19 52 32

Thanks! This was helpful. Looks like this is the same issue as #22692, so I will close this in favor of the issue I linked to. I have an idea of how to fix this issue, so I will try to get a dev build for you to test today/tomorrow.

@liamdebeasi
Copy link
Contributor

I posted a dev build on this thread: #22692 (comment)

@cdes
Copy link
Contributor Author

cdes commented Mar 18, 2021

@liamdebeasi IT WORKS!

https://codesandbox.io/s/ionic-recursive-route-570-dev2021031813498ac4d12-wzoyl

CleanShot 2021-03-18 at 19 47 45

@liamdebeasi
Copy link
Contributor

Glad it's working now! I will try to get that PR merged in soon.

@ionitron-bot
Copy link

ionitron-bot bot commented Apr 17, 2021

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 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants