-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(react-router): resolve relative route matching inside root-level splat routes #30861
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
Merged
ShaneK
merged 5 commits into
fix/react-router-6-paths
from
fix/react-router-6-splat-links
Dec 12, 2025
+655
−38
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e7051a
fix(react-router): fix relative link resolution in nested outlets wit…
ShaneK 17902a6
Merge branch 'fix/react-router-6-paths' of github.com:ionic-team/ioni…
ShaneK f70231a
fix(react-router): resolve relative route matching inside root-level …
ShaneK 04dd740
chore(react-router): adding links to E2E tests
ShaneK 918281b
chore(react-router): comment clarity
ShaneK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ShaneK marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
...s/react-router/test/base/src/pages/nested-tabs-relative-links/NestedTabsRelativeLinks.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import { | ||
| IonContent, | ||
| IonHeader, | ||
| IonPage, | ||
| IonTitle, | ||
| IonToolbar, | ||
| IonRouterOutlet, | ||
| IonTabs, | ||
| IonTabBar, | ||
| IonTabButton, | ||
| IonIcon, | ||
| IonLabel, | ||
| IonBackButton, | ||
| IonButtons, | ||
| } from '@ionic/react'; | ||
| import { triangle, ellipse, square } from 'ionicons/icons'; | ||
| import React from 'react'; | ||
| import { Link, Navigate, Route } from 'react-router-dom'; | ||
|
|
||
| /** | ||
| * This test page verifies that relative links work correctly within | ||
| * nested IonRouterOutlet components, specifically in a tabs-based layout. | ||
| * | ||
| * Issue: When using React Router's <Link to="page-a"> inside the tab1 route | ||
| * with nested outlets and index routes, the relative path resolution can produce | ||
| * incorrect URLs (e.g., /tab1/tab1/page-a instead of /tab1/page-a). | ||
| * | ||
| * This test also verifies that absolute links work when a catch-all route | ||
| * is present. | ||
| */ | ||
|
|
||
| // Tab content with relative links for testing | ||
| const Tab1Content: React.FC = () => { | ||
| return ( | ||
| <IonPage data-pageid="nested-tabs-relative-tab1"> | ||
| <IonHeader> | ||
| <IonToolbar> | ||
| <IonTitle>Tab 1</IonTitle> | ||
| </IonToolbar> | ||
| </IonHeader> | ||
| <IonContent> | ||
| <div data-testid="tab1-content"> | ||
| <p>Tab 1 - Home Page</p> | ||
| {/* Relative link - should navigate to /nested-tabs-relative-links/tab1/page-a */} | ||
| <Link to="page-a" data-testid="link-relative-page-a"> | ||
| Go to Page A (relative) | ||
| </Link> | ||
| <br /> | ||
| {/* Absolute link - should also work */} | ||
| <Link to="/nested-tabs-relative-links/tab1/page-a" data-testid="link-absolute-page-a"> | ||
| Go to Page A (absolute) | ||
| </Link> | ||
| <br /> | ||
| {/* Another relative link */} | ||
| <Link to="page-b" data-testid="link-relative-page-b"> | ||
| Go to Page B (relative) | ||
| </Link> | ||
| </div> | ||
| </IonContent> | ||
| </IonPage> | ||
| ); | ||
| }; | ||
|
|
||
| const PageA: React.FC = () => { | ||
| return ( | ||
| <IonPage data-pageid="nested-tabs-relative-page-a"> | ||
| <IonHeader> | ||
| <IonToolbar> | ||
| <IonButtons slot="start"> | ||
| <IonBackButton defaultHref="/nested-tabs-relative-links/tab1" /> | ||
| </IonButtons> | ||
| <IonTitle>Page A</IonTitle> | ||
| </IonToolbar> | ||
| </IonHeader> | ||
| <IonContent> | ||
| <div data-testid="page-a-content"> | ||
| This is Page A within Tab 1 | ||
| </div> | ||
| </IonContent> | ||
| </IonPage> | ||
| ); | ||
| }; | ||
|
|
||
| const PageB: React.FC = () => { | ||
| return ( | ||
| <IonPage data-pageid="nested-tabs-relative-page-b"> | ||
| <IonHeader> | ||
| <IonToolbar> | ||
| <IonButtons slot="start"> | ||
| <IonBackButton defaultHref="/nested-tabs-relative-links/tab1" /> | ||
| </IonButtons> | ||
| <IonTitle>Page B</IonTitle> | ||
| </IonToolbar> | ||
| </IonHeader> | ||
| <IonContent> | ||
| <div data-testid="page-b-content"> | ||
| This is Page B within Tab 1 | ||
| </div> | ||
| </IonContent> | ||
| </IonPage> | ||
| ); | ||
| }; | ||
|
|
||
| // Nested router outlet for Tab 1 - similar to user's RouterOutletTab1 | ||
| const Tab1RouterOutlet: React.FC = () => { | ||
| return ( | ||
| <IonRouterOutlet> | ||
| <Route index element={<Tab1Content />} /> | ||
| <Route path="page-a" element={<PageA />} /> | ||
| <Route path="page-b" element={<PageB />} /> | ||
| </IonRouterOutlet> | ||
| ); | ||
| }; | ||
|
|
||
| const Tab2Content: React.FC = () => { | ||
| return ( | ||
| <IonPage data-pageid="nested-tabs-relative-tab2"> | ||
| <IonHeader> | ||
| <IonToolbar> | ||
| <IonTitle>Tab 2</IonTitle> | ||
| </IonToolbar> | ||
| </IonHeader> | ||
| <IonContent> | ||
| <div data-testid="tab2-content"> | ||
| Tab 2 Content | ||
| </div> | ||
| </IonContent> | ||
| </IonPage> | ||
| ); | ||
| }; | ||
|
|
||
| const Tab3Content: React.FC = () => { | ||
| return ( | ||
| <IonPage data-pageid="nested-tabs-relative-tab3"> | ||
| <IonHeader> | ||
| <IonToolbar> | ||
| <IonTitle>Tab 3</IonTitle> | ||
| </IonToolbar> | ||
| </IonHeader> | ||
| <IonContent> | ||
| <div data-testid="tab3-content"> | ||
| Tab 3 Content | ||
| </div> | ||
| </IonContent> | ||
| </IonPage> | ||
| ); | ||
| }; | ||
|
|
||
| // Main tabs component - wraps tabs with catch-all route (similar to user's reproduction) | ||
| const TabsContainer: React.FC = () => ( | ||
| <IonTabs> | ||
| <IonRouterOutlet> | ||
| {/* Tab 1 has nested routes with index route */} | ||
| <Route path="tab1/*" element={<Tab1RouterOutlet />} /> | ||
| <Route path="tab2" element={<Tab2Content />} /> | ||
| <Route path="tab3" element={<Tab3Content />} /> | ||
| <Route index element={<Navigate to="tab1" replace />} /> | ||
| {/* Catch-all 404 route - this presence caused issues with absolute links */} | ||
| <Route | ||
| path="*" | ||
| element={ | ||
| <IonPage data-pageid="nested-tabs-relative-404"> | ||
| <IonContent> | ||
| <p data-testid="not-found">404 - Not Found</p> | ||
| </IonContent> | ||
| </IonPage> | ||
| } | ||
| /> | ||
| </IonRouterOutlet> | ||
| <IonTabBar slot="bottom"> | ||
| <IonTabButton tab="tab1" href="/nested-tabs-relative-links/tab1"> | ||
| <IonIcon icon={triangle} /> | ||
| <IonLabel>Tab 1</IonLabel> | ||
| </IonTabButton> | ||
| <IonTabButton tab="tab2" href="/nested-tabs-relative-links/tab2"> | ||
| <IonIcon icon={ellipse} /> | ||
| <IonLabel>Tab 2</IonLabel> | ||
| </IonTabButton> | ||
| <IonTabButton tab="tab3" href="/nested-tabs-relative-links/tab3"> | ||
| <IonIcon icon={square} /> | ||
| <IonLabel>Tab 3</IonLabel> | ||
| </IonTabButton> | ||
| </IonTabBar> | ||
| </IonTabs> | ||
| ); | ||
|
|
||
| // Top-level component - splat route renders tabs | ||
| const NestedTabsRelativeLinks: React.FC = () => ( | ||
| <IonRouterOutlet> | ||
| <Route path="*" element={<TabsContainer />} /> | ||
| </IonRouterOutlet> | ||
| ); | ||
|
|
||
| export default NestedTabsRelativeLinks; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.