react-router 0.0.0-experimental-9463fb5e → 0.0.0-experimental-8bb3ffdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +141 -0
- package/dist/index.js +26 -19
- package/dist/index.js.map +1 -1
- package/dist/lib/components.d.ts +1 -3
- package/dist/lib/context.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +26 -19
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +26 -19
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,146 @@
|
|
|
1
1
|
# `react-router`
|
|
2
2
|
|
|
3
|
+
## 6.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add a new `future.v7_relativeSplatPath` flag to implement a breaking bug fix to relative routing when inside a splat route. ([#11087](https://github.com/remix-run/react-router/pull/11087))
|
|
8
|
+
|
|
9
|
+
This fix was originally added in [#10983](https://github.com/remix-run/react-router/issues/10983) and was later reverted in [#11078](https://github.com/remix-run/react-router/pull/11078) because it was determined that a large number of existing applications were relying on the buggy behavior (see [#11052](https://github.com/remix-run/react-router/issues/11052))
|
|
10
|
+
|
|
11
|
+
**The Bug**
|
|
12
|
+
The buggy behavior is that without this flag, the default behavior when resolving relative paths is to _ignore_ any splat (`*`) portion of the current route path.
|
|
13
|
+
|
|
14
|
+
**The Background**
|
|
15
|
+
This decision was originally made thinking that it would make the concept of nested different sections of your apps in `<Routes>` easier if relative routing would _replace_ the current splat:
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
<BrowserRouter>
|
|
19
|
+
<Routes>
|
|
20
|
+
<Route path="/" element={<Home />} />
|
|
21
|
+
<Route path="dashboard/*" element={<Dashboard />} />
|
|
22
|
+
</Routes>
|
|
23
|
+
</BrowserRouter>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Any paths like `/dashboard`, `/dashboard/team`, `/dashboard/projects` will match the `Dashboard` route. The dashboard component itself can then render nested `<Routes>`:
|
|
27
|
+
|
|
28
|
+
```jsx
|
|
29
|
+
function Dashboard() {
|
|
30
|
+
return (
|
|
31
|
+
<div>
|
|
32
|
+
<h2>Dashboard</h2>
|
|
33
|
+
<nav>
|
|
34
|
+
<Link to="/">Dashboard Home</Link>
|
|
35
|
+
<Link to="team">Team</Link>
|
|
36
|
+
<Link to="projects">Projects</Link>
|
|
37
|
+
</nav>
|
|
38
|
+
|
|
39
|
+
<Routes>
|
|
40
|
+
<Route path="/" element={<DashboardHome />} />
|
|
41
|
+
<Route path="team" element={<DashboardTeam />} />
|
|
42
|
+
<Route path="projects" element={<DashboardProjects />} />
|
|
43
|
+
</Routes>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Now, all links and route paths are relative to the router above them. This makes code splitting and compartmentalizing your app really easy. You could render the `Dashboard` as its own independent app, or embed it into your large app without making any changes to it.
|
|
50
|
+
|
|
51
|
+
**The Problem**
|
|
52
|
+
|
|
53
|
+
The problem is that this concept of ignoring part of a path breaks a lot of other assumptions in React Router - namely that `"."` always means the current location pathname for that route. When we ignore the splat portion, we start getting invalid paths when using `"."`:
|
|
54
|
+
|
|
55
|
+
```jsx
|
|
56
|
+
// If we are on URL /dashboard/team, and we want to link to /dashboard/team:
|
|
57
|
+
function DashboardTeam() {
|
|
58
|
+
// ❌ This is broken and results in <a href="/dashboard">
|
|
59
|
+
return <Link to=".">A broken link to the Current URL</Link>;
|
|
60
|
+
|
|
61
|
+
// ✅ This is fixed but super unintuitive since we're already at /dashboard/team!
|
|
62
|
+
return <Link to="./team">A broken link to the Current URL</Link>;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
We've also introduced an issue that we can no longer move our `DashboardTeam` component around our route hierarchy easily - since it behaves differently if we're underneath a non-splat route, such as `/dashboard/:widget`. Now, our `"."` links will, properly point to ourself _inclusive of the dynamic param value_ so behavior will break from it's corresponding usage in a `/dashboard/*` route.
|
|
67
|
+
|
|
68
|
+
Even worse, consider a nested splat route configuration:
|
|
69
|
+
|
|
70
|
+
```jsx
|
|
71
|
+
<BrowserRouter>
|
|
72
|
+
<Routes>
|
|
73
|
+
<Route path="dashboard">
|
|
74
|
+
<Route path="*" element={<Dashboard />} />
|
|
75
|
+
</Route>
|
|
76
|
+
</Routes>
|
|
77
|
+
</BrowserRouter>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Now, a `<Link to=".">` and a `<Link to="..">` inside the `Dashboard` component go to the same place! That is definitely not correct!
|
|
81
|
+
|
|
82
|
+
Another common issue arose in Data Routers (and Remix) where any `<Form>` should post to it's own route `action` if you the user doesn't specify a form action:
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
let router = createBrowserRouter({
|
|
86
|
+
path: "/dashboard",
|
|
87
|
+
children: [
|
|
88
|
+
{
|
|
89
|
+
path: "*",
|
|
90
|
+
action: dashboardAction,
|
|
91
|
+
Component() {
|
|
92
|
+
// ❌ This form is broken! It throws a 405 error when it submits because
|
|
93
|
+
// it tries to submit to /dashboard (without the splat value) and the parent
|
|
94
|
+
// `/dashboard` route doesn't have an action
|
|
95
|
+
return <Form method="post">...</Form>;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This is just a compounded issue from the above because the default location for a `Form` to submit to is itself (`"."`) - and if we ignore the splat portion, that now resolves to the parent route.
|
|
103
|
+
|
|
104
|
+
**The Solution**
|
|
105
|
+
If you are leveraging this behavior, it's recommended to enable the future flag, move your splat to it's own route, and leverage `../` for any links to "sibling" pages:
|
|
106
|
+
|
|
107
|
+
```jsx
|
|
108
|
+
<BrowserRouter>
|
|
109
|
+
<Routes>
|
|
110
|
+
<Route path="dashboard">
|
|
111
|
+
<Route path="*" element={<Dashboard />} />
|
|
112
|
+
</Route>
|
|
113
|
+
</Routes>
|
|
114
|
+
</BrowserRouter>
|
|
115
|
+
|
|
116
|
+
function Dashboard() {
|
|
117
|
+
return (
|
|
118
|
+
<div>
|
|
119
|
+
<h2>Dashboard</h2>
|
|
120
|
+
<nav>
|
|
121
|
+
<Link to="..">Dashboard Home</Link>
|
|
122
|
+
<Link to="../team">Team</Link>
|
|
123
|
+
<Link to="../projects">Projects</Link>
|
|
124
|
+
</nav>
|
|
125
|
+
|
|
126
|
+
<Routes>
|
|
127
|
+
<Route path="/" element={<DashboardHome />} />
|
|
128
|
+
<Route path="team" element={<DashboardTeam />} />
|
|
129
|
+
<Route path="projects" element={<DashboardProjects />} />
|
|
130
|
+
</Router>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This way, `.` means "the full current pathname for my route" in all cases (including static, dynamic, and splat routes) and `..` always means "my parents pathname".
|
|
137
|
+
|
|
138
|
+
### Patch Changes
|
|
139
|
+
|
|
140
|
+
- Properly handle falsy error values in ErrorBoundary's ([#11071](https://github.com/remix-run/react-router/pull/11071))
|
|
141
|
+
- Updated dependencies:
|
|
142
|
+
- `@remix-run/router@1.14.0`
|
|
143
|
+
|
|
3
144
|
## 6.20.1
|
|
4
145
|
|
|
5
146
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-8bb3ffdf
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -378,7 +378,7 @@ function useRoutesImpl(routes, locationArg, dataRouterState, future) {
|
|
|
378
378
|
});
|
|
379
379
|
if (process.env.NODE_ENV !== "production") {
|
|
380
380
|
process.env.NODE_ENV !== "production" ? UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
|
|
381
|
-
process.env.NODE_ENV !== "production" ? UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" " + "does not have an element or Component. This means it will render an <Outlet /> with a " + "null value by default resulting in an \"empty\" page.") : void 0;
|
|
381
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined || matches[matches.length - 1].route.lazy !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" " + "does not have an element or Component. This means it will render an <Outlet /> with a " + "null value by default resulting in an \"empty\" page.") : void 0;
|
|
382
382
|
}
|
|
383
383
|
let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
|
384
384
|
params: Object.assign({}, parentParams, match.params),
|
|
@@ -552,17 +552,24 @@ function _renderMatches(matches, parentMatches, dataRouterState, future) {
|
|
|
552
552
|
if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
|
|
553
553
|
fallbackIndex = i;
|
|
554
554
|
}
|
|
555
|
-
if (match.route.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
555
|
+
if (match.route.id) {
|
|
556
|
+
let {
|
|
557
|
+
loaderData,
|
|
558
|
+
errors
|
|
559
|
+
} = dataRouterState;
|
|
560
|
+
let needsToRunLoader = match.route.loader && loaderData[match.route.id] === undefined && (!errors || errors[match.route.id] === undefined);
|
|
561
|
+
if (match.route.lazy || needsToRunLoader) {
|
|
562
|
+
// We found the first route that's not ready to render (waiting on
|
|
563
|
+
// lazy, or has a loader that hasn't run yet). Flag that we need to
|
|
564
|
+
// render a fallback and render up until the appropriate fallback
|
|
565
|
+
renderFallback = true;
|
|
566
|
+
if (fallbackIndex >= 0) {
|
|
567
|
+
renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
|
|
568
|
+
} else {
|
|
569
|
+
renderedMatches = [renderedMatches[0]];
|
|
570
|
+
}
|
|
571
|
+
break;
|
|
564
572
|
}
|
|
565
|
-
break;
|
|
566
573
|
}
|
|
567
574
|
}
|
|
568
575
|
}
|
|
@@ -940,7 +947,7 @@ function RouterProvider(_ref) {
|
|
|
940
947
|
// pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
|
|
941
948
|
React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
|
|
942
949
|
React.useEffect(() => {
|
|
943
|
-
process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`") : void 0;
|
|
950
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") : void 0;
|
|
944
951
|
// Only log this once on initial mount
|
|
945
952
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
946
953
|
}, []);
|
|
@@ -965,10 +972,7 @@ function RouterProvider(_ref) {
|
|
|
965
972
|
router,
|
|
966
973
|
navigator,
|
|
967
974
|
static: false,
|
|
968
|
-
basename
|
|
969
|
-
future: {
|
|
970
|
-
v7_relativeSplatPath: router.future.v7_relativeSplatPath
|
|
971
|
-
}
|
|
975
|
+
basename
|
|
972
976
|
}), [router, navigator, basename]);
|
|
973
977
|
|
|
974
978
|
// The fragment and {null} here are important! We need them to keep React 18's
|
|
@@ -985,8 +989,11 @@ function RouterProvider(_ref) {
|
|
|
985
989
|
basename: basename,
|
|
986
990
|
location: state.location,
|
|
987
991
|
navigationType: state.historyAction,
|
|
988
|
-
navigator: navigator
|
|
989
|
-
|
|
992
|
+
navigator: navigator,
|
|
993
|
+
future: {
|
|
994
|
+
v7_relativeSplatPath: router.future.v7_relativeSplatPath
|
|
995
|
+
}
|
|
996
|
+
}, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(DataRoutes, {
|
|
990
997
|
routes: router.routes,
|
|
991
998
|
future: router.future,
|
|
992
999
|
state: state
|