|
| 1 | +import { |
| 2 | + IonButton, |
| 3 | + IonContent, |
| 4 | + IonHeader, |
| 5 | + IonLabel, |
| 6 | + IonPage, |
| 7 | + IonRouterOutlet, |
| 8 | + IonTitle, |
| 9 | + IonToolbar, |
| 10 | +} from '@ionic/react'; |
| 11 | +import React from 'react'; |
| 12 | +import { Route, useLocation, useParams } from 'react-router-dom'; |
| 13 | + |
| 14 | +/** |
| 15 | + * Test page for empty-path route deactivation behavior. |
| 16 | + * |
| 17 | + * Route structure: |
| 18 | + * /empty-path-deactivation/* |
| 19 | + * └── <IonRouterOutlet> |
| 20 | + * ├── path="" → DefaultPage (matches at /empty-path-deactivation) |
| 21 | + * ├── path="details/:id" → DetailsPage |
| 22 | + * └── path="*" → CatchAllPage |
| 23 | + * |
| 24 | + * Bug scenario: |
| 25 | + * 1. Navigate to /empty-path-deactivation → DefaultPage shows (path="" matches) |
| 26 | + * 2. Navigate to /empty-path-deactivation/details/42 → DetailsPage shows |
| 27 | + * 3. Navigate to /empty-path-deactivation/extra/details/99 |
| 28 | + * 4. derivePathnameToMatch tail-slices ["details","99"] → false match on details/:id |
| 29 | + * 5. hasSpecificMatch becomes true → path="" view set to mount=false + ion-page-hidden |
| 30 | + * 6. Navigate back to /empty-path-deactivation → DefaultPage may remain hidden |
| 31 | + * |
| 32 | + * Uses path="" (not index) to test a different code path from the |
| 33 | + * tail-slice-ambiguity test which uses <Route index>. |
| 34 | + */ |
| 35 | +const EmptyPathDeactivation: React.FC = () => ( |
| 36 | + <IonRouterOutlet id="empty-path-outlet"> |
| 37 | + <Route path="" element={<DefaultPage />} /> |
| 38 | + <Route path="details/:id" element={<DetailsPage />} /> |
| 39 | + <Route path="*" element={<CatchAllPage />} /> |
| 40 | + </IonRouterOutlet> |
| 41 | +); |
| 42 | + |
| 43 | +const DefaultPage: React.FC = () => ( |
| 44 | + <IonPage data-pageid="empty-path-default"> |
| 45 | + <IonHeader> |
| 46 | + <IonToolbar> |
| 47 | + <IonTitle>Default</IonTitle> |
| 48 | + </IonToolbar> |
| 49 | + </IonHeader> |
| 50 | + <IonContent> |
| 51 | + <IonLabel data-testid="default-label">Default Page Content</IonLabel> |
| 52 | + <IonButton routerLink="/empty-path-deactivation/details/42" id="go-to-details"> |
| 53 | + Details 42 |
| 54 | + </IonButton> |
| 55 | + <IonButton routerLink="/empty-path-deactivation/extra/details/99" id="go-to-ambiguous"> |
| 56 | + Ambiguous Path |
| 57 | + </IonButton> |
| 58 | + </IonContent> |
| 59 | + </IonPage> |
| 60 | +); |
| 61 | + |
| 62 | +const DetailsPage: React.FC = () => { |
| 63 | + const { id } = useParams<{ id: string }>(); |
| 64 | + return ( |
| 65 | + <IonPage data-pageid="empty-path-details"> |
| 66 | + <IonHeader> |
| 67 | + <IonToolbar> |
| 68 | + <IonTitle>Details</IonTitle> |
| 69 | + </IonToolbar> |
| 70 | + </IonHeader> |
| 71 | + <IonContent> |
| 72 | + <IonLabel data-testid="details-id">Details ID: {id}</IonLabel> |
| 73 | + <IonButton routerLink="/empty-path-deactivation" id="back-to-default"> |
| 74 | + Back to Default |
| 75 | + </IonButton> |
| 76 | + </IonContent> |
| 77 | + </IonPage> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +const CatchAllPage: React.FC = () => { |
| 82 | + const location = useLocation(); |
| 83 | + return ( |
| 84 | + <IonPage data-pageid="empty-path-catchall"> |
| 85 | + <IonHeader> |
| 86 | + <IonToolbar> |
| 87 | + <IonTitle>Catch All</IonTitle> |
| 88 | + </IonToolbar> |
| 89 | + </IonHeader> |
| 90 | + <IonContent> |
| 91 | + <IonLabel data-testid="catchall-path">Catch-all: {location.pathname}</IonLabel> |
| 92 | + <IonButton routerLink="/empty-path-deactivation" id="catchall-back-to-default"> |
| 93 | + Back to Default |
| 94 | + </IonButton> |
| 95 | + </IonContent> |
| 96 | + </IonPage> |
| 97 | + ); |
| 98 | +}; |
| 99 | + |
| 100 | +export default EmptyPathDeactivation; |
0 commit comments