Skip to content

Commit cc4436c

Browse files
committed
Update changelogs for useResolvedSplat example
1 parent d9b36f6 commit cc4436c

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

docs/hooks/use-resolved-path.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,30 @@ And then it gets worse if you define the splat route as a child:
6060
<BrowserRouter>
6161
<Routes>
6262
<Route path="/dashboard">
63-
<Route index path="*" element={<Dashboard />} />
63+
<Route path="*" element={<Dashboard />} />
6464
</Route>
6565
</Routes>
6666
</BrowserRouter>
6767
```
6868

6969
- Now, `useResolvedPath(".")` and `useResolvedPath("..")` resolve to the exact same path inside `<Dashboard />`
70-
- If you were using a Data Router and defined an `action` on the splat route, you'd get a 405 error on `<Form>` submissions because they (by default) submit to `"."` which would resolve to the parent `/dashboard` route which doesn't have an `action`.
70+
- If you were using a Data Router and defined an `action` on the splat route, you'd get a 405 error on `<Form>` submissions inside `<Dashboard>` because they (by default) submit to `"."` which would resolve to the parent `/dashboard` route which doesn't have an `action`.
7171

7272
### Behavior with the flag
7373

7474
When you enable the flag, this "bug" is fixed so that path resolution is consistent across all route types, and `useResolvedPath(".")` always resolves to the current pathname for the contextual route. This includes any dynamic param or splat param values.
7575

76-
If you want to navigate between "sibling" routes within a splat route, it is suggested you move your splat route to it's own child (`<Route index path="*" element={<Dashboard />} />`) and use `useResolvedPath("../teams")` and `useResolvedPath("../projects")` parent-relative paths to navigate to sibling `/dashboard` routes.
76+
If you want to navigate between "sibling" routes within a splat route, it is suggested you move your splat route to it's own child and use `useResolvedPath("../teams")` and `useResolvedPath("../projects")` parent-relative paths to navigate to sibling `/dashboard` routes. Note that here we also use `index` so that the URL `/dashboard` also renders the `<Dashboard>` component.
77+
78+
```jsx
79+
<BrowserRouter>
80+
<Routes>
81+
<Route path="/dashboard">
82+
<Route index path="*" element={<Dashboard />} />
83+
</Route>
84+
</Routes>
85+
</BrowserRouter>
86+
```
7787

7888
[navlink]: ../components/nav-link
7989
[resolvepath]: ../utils/resolve-path

packages/react-router-dom-v5-compat/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<BrowserRouter>
109109
<Routes>
110110
<Route path="dashboard">
111-
<Route path="*" element={<Dashboard />} />
111+
<Route index path="*" element={<Dashboard />} />
112112
</Route>
113113
</Routes>
114114
</BrowserRouter>

packages/react-router-dom/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<BrowserRouter>
109109
<Routes>
110110
<Route path="dashboard">
111-
<Route path="*" element={<Dashboard />} />
111+
<Route index path="*" element={<Dashboard />} />
112112
</Route>
113113
</Routes>
114114
</BrowserRouter>

packages/react-router-native/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<BrowserRouter>
109109
<Routes>
110110
<Route path="dashboard">
111-
<Route path="*" element={<Dashboard />} />
111+
<Route index path="*" element={<Dashboard />} />
112112
</Route>
113113
</Routes>
114114
</BrowserRouter>

packages/react-router/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<BrowserRouter>
109109
<Routes>
110110
<Route path="dashboard">
111-
<Route path="*" element={<Dashboard />} />
111+
<Route index path="*" element={<Dashboard />} />
112112
</Route>
113113
</Routes>
114114
</BrowserRouter>

packages/router/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
<BrowserRouter>
150150
<Routes>
151151
<Route path="dashboard">
152-
<Route path="*" element={<Dashboard />} />
152+
<Route index path="*" element={<Dashboard />} />
153153
</Route>
154154
</Routes>
155155
</BrowserRouter>

0 commit comments

Comments
 (0)