react-router-dom 5.2.0 → 6.11.2
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 +345 -0
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +4 -36
- package/dist/dom.d.ts +76 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +1058 -0
- package/dist/index.js.map +1 -0
- package/dist/main.js +19 -0
- package/dist/react-router-dom.development.js +1005 -0
- package/dist/react-router-dom.development.js.map +1 -0
- package/dist/react-router-dom.production.min.js +12 -0
- package/dist/react-router-dom.production.min.js.map +1 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.js +319 -0
- package/dist/server.mjs +291 -0
- package/dist/umd/react-router-dom.development.js +1306 -0
- package/dist/umd/react-router-dom.development.js.map +1 -0
- package/dist/umd/react-router-dom.production.min.js +12 -0
- package/dist/umd/react-router-dom.production.min.js.map +1 -0
- package/package.json +38 -54
- package/server.d.ts +28 -0
- package/server.js +319 -0
- package/server.mjs +291 -0
- package/BrowserRouter.js +0 -3
- package/HashRouter.js +0 -3
- package/Link.js +0 -3
- package/MemoryRouter.js +0 -3
- package/NavLink.js +0 -3
- package/Prompt.js +0 -3
- package/Redirect.js +0 -3
- package/Route.js +0 -3
- package/Router.js +0 -3
- package/StaticRouter.js +0 -3
- package/Switch.js +0 -3
- package/cjs/react-router-dom.js +0 -443
- package/cjs/react-router-dom.js.map +0 -1
- package/cjs/react-router-dom.min.js +0 -2
- package/cjs/react-router-dom.min.js.map +0 -1
- package/es/BrowserRouter.js +0 -5
- package/es/HashRouter.js +0 -5
- package/es/Link.js +0 -5
- package/es/MemoryRouter.js +0 -5
- package/es/NavLink.js +0 -5
- package/es/Prompt.js +0 -5
- package/es/Redirect.js +0 -5
- package/es/Route.js +0 -5
- package/es/Router.js +0 -5
- package/es/StaticRouter.js +0 -5
- package/es/Switch.js +0 -5
- package/es/generatePath.js +0 -5
- package/es/matchPath.js +0 -5
- package/es/warnAboutDeprecatedESMImport.js +0 -34
- package/es/withRouter.js +0 -5
- package/esm/react-router-dom.js +0 -317
- package/esm/react-router-dom.js.map +0 -1
- package/generatePath.js +0 -3
- package/index.js +0 -7
- package/matchPath.js +0 -3
- package/modules/BrowserRouter.js +0 -36
- package/modules/HashRouter.js +0 -35
- package/modules/Link.js +0 -146
- package/modules/NavLink.js +0 -125
- package/modules/index.js +0 -21
- package/modules/utils/locationUtils.js +0 -10
- package/umd/react-router-dom.js +0 -3969
- package/umd/react-router-dom.js.map +0 -1
- package/umd/react-router-dom.min.js +0 -2
- package/umd/react-router-dom.min.js.map +0 -1
- package/warnAboutDeprecatedCJSRequire.js +0 -36
- package/withRouter.js +0 -3
package/server.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var router = require('@remix-run/router');
|
|
7
|
+
var reactRouter = require('react-router');
|
|
8
|
+
var reactRouterDom = require('react-router-dom');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A <Router> that may not navigate to any other location. This is useful
|
|
32
|
+
* on the server where there is no stateful UI.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function StaticRouter({
|
|
36
|
+
basename,
|
|
37
|
+
children,
|
|
38
|
+
location: locationProp = "/"
|
|
39
|
+
}) {
|
|
40
|
+
if (typeof locationProp === "string") {
|
|
41
|
+
locationProp = reactRouterDom.parsePath(locationProp);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let action = router.Action.Pop;
|
|
45
|
+
let location = {
|
|
46
|
+
pathname: locationProp.pathname || "/",
|
|
47
|
+
search: locationProp.search || "",
|
|
48
|
+
hash: locationProp.hash || "",
|
|
49
|
+
state: locationProp.state || null,
|
|
50
|
+
key: locationProp.key || "default"
|
|
51
|
+
};
|
|
52
|
+
let staticNavigator = getStatelessNavigator();
|
|
53
|
+
return /*#__PURE__*/React__namespace.createElement(reactRouterDom.Router, {
|
|
54
|
+
basename: basename,
|
|
55
|
+
children: children,
|
|
56
|
+
location: location,
|
|
57
|
+
navigationType: action,
|
|
58
|
+
navigator: staticNavigator,
|
|
59
|
+
static: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A Data Router that may not navigate to any other location. This is useful
|
|
64
|
+
* on the server where there is no stateful UI.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
function StaticRouterProvider({
|
|
68
|
+
context,
|
|
69
|
+
router: router$1,
|
|
70
|
+
hydrate = true,
|
|
71
|
+
nonce
|
|
72
|
+
}) {
|
|
73
|
+
!(router$1 && context) ? process.env.NODE_ENV !== "production" ? router.UNSAFE_invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : router.UNSAFE_invariant(false) : void 0;
|
|
74
|
+
let dataRouterContext = {
|
|
75
|
+
router: router$1,
|
|
76
|
+
navigator: getStatelessNavigator(),
|
|
77
|
+
static: true,
|
|
78
|
+
staticContext: context,
|
|
79
|
+
basename: context.basename || "/"
|
|
80
|
+
};
|
|
81
|
+
let hydrateScript = "";
|
|
82
|
+
|
|
83
|
+
if (hydrate !== false) {
|
|
84
|
+
let data = {
|
|
85
|
+
loaderData: context.loaderData,
|
|
86
|
+
actionData: context.actionData,
|
|
87
|
+
errors: serializeErrors(context.errors)
|
|
88
|
+
}; // Use JSON.parse here instead of embedding a raw JS object here to speed
|
|
89
|
+
// up parsing on the client. Dual-stringify is needed to ensure all quotes
|
|
90
|
+
// are properly escaped in the resulting string. See:
|
|
91
|
+
// https://v8.dev/blog/cost-of-javascript-2019#json
|
|
92
|
+
|
|
93
|
+
let json = htmlEscape(JSON.stringify(JSON.stringify(data)));
|
|
94
|
+
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let {
|
|
98
|
+
state
|
|
99
|
+
} = dataRouterContext.router;
|
|
100
|
+
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(reactRouterDom.UNSAFE_DataRouterContext.Provider, {
|
|
101
|
+
value: dataRouterContext
|
|
102
|
+
}, /*#__PURE__*/React__namespace.createElement(reactRouterDom.UNSAFE_DataRouterStateContext.Provider, {
|
|
103
|
+
value: state
|
|
104
|
+
}, /*#__PURE__*/React__namespace.createElement(reactRouterDom.Router, {
|
|
105
|
+
basename: dataRouterContext.basename,
|
|
106
|
+
location: state.location,
|
|
107
|
+
navigationType: state.historyAction,
|
|
108
|
+
navigator: dataRouterContext.navigator,
|
|
109
|
+
static: dataRouterContext.static
|
|
110
|
+
}, /*#__PURE__*/React__namespace.createElement(DataRoutes, {
|
|
111
|
+
routes: router$1.routes,
|
|
112
|
+
state: state
|
|
113
|
+
})))), hydrateScript ? /*#__PURE__*/React__namespace.createElement("script", {
|
|
114
|
+
suppressHydrationWarning: true,
|
|
115
|
+
nonce: nonce,
|
|
116
|
+
dangerouslySetInnerHTML: {
|
|
117
|
+
__html: hydrateScript
|
|
118
|
+
}
|
|
119
|
+
}) : null);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function DataRoutes({
|
|
123
|
+
routes,
|
|
124
|
+
state
|
|
125
|
+
}) {
|
|
126
|
+
return reactRouter.UNSAFE_useRoutesImpl(routes, undefined, state);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function serializeErrors(errors) {
|
|
130
|
+
if (!errors) return null;
|
|
131
|
+
let entries = Object.entries(errors);
|
|
132
|
+
let serialized = {};
|
|
133
|
+
|
|
134
|
+
for (let [key, val] of entries) {
|
|
135
|
+
// Hey you! If you change this, please change the corresponding logic in
|
|
136
|
+
// deserializeErrors in react-router-dom/index.tsx :)
|
|
137
|
+
if (router.isRouteErrorResponse(val)) {
|
|
138
|
+
serialized[key] = { ...val,
|
|
139
|
+
__type: "RouteErrorResponse"
|
|
140
|
+
};
|
|
141
|
+
} else if (val instanceof Error) {
|
|
142
|
+
// Do not serialize stack traces from SSR for security reasons
|
|
143
|
+
serialized[key] = {
|
|
144
|
+
message: val.message,
|
|
145
|
+
__type: "Error"
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
serialized[key] = val;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return serialized;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function getStatelessNavigator() {
|
|
156
|
+
return {
|
|
157
|
+
createHref,
|
|
158
|
+
encodeLocation,
|
|
159
|
+
|
|
160
|
+
push(to) {
|
|
161
|
+
throw new Error(`You cannot use navigator.push() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)})\` somewhere in your app.`);
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
replace(to) {
|
|
165
|
+
throw new Error(`You cannot use navigator.replace() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere ` + `in your app.`);
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
go(delta) {
|
|
169
|
+
throw new Error(`You cannot use navigator.go() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${delta})\` somewhere in your app.`);
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
back() {
|
|
173
|
+
throw new Error(`You cannot use navigator.back() on the server because it is a stateless ` + `environment.`);
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
forward() {
|
|
177
|
+
throw new Error(`You cannot use navigator.forward() on the server because it is a stateless ` + `environment.`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function createStaticHandler(routes, opts) {
|
|
184
|
+
return router.createStaticHandler(routes, { ...opts,
|
|
185
|
+
mapRouteProperties: reactRouter.UNSAFE_mapRouteProperties
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function createStaticRouter(routes, context) {
|
|
189
|
+
let manifest = {};
|
|
190
|
+
let dataRoutes = router.UNSAFE_convertRoutesToDataRoutes(routes, reactRouter.UNSAFE_mapRouteProperties, undefined, manifest); // Because our context matches may be from a framework-agnostic set of
|
|
191
|
+
// routes passed to createStaticHandler(), we update them here with our
|
|
192
|
+
// newly created/enhanced data routes
|
|
193
|
+
|
|
194
|
+
let matches = context.matches.map(match => {
|
|
195
|
+
let route = manifest[match.route.id] || match.route;
|
|
196
|
+
return { ...match,
|
|
197
|
+
route
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
let msg = method => `You cannot use router.${method}() on the server because it is a stateless environment`;
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
get basename() {
|
|
205
|
+
return context.basename;
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
get state() {
|
|
209
|
+
return {
|
|
210
|
+
historyAction: router.Action.Pop,
|
|
211
|
+
location: context.location,
|
|
212
|
+
matches,
|
|
213
|
+
loaderData: context.loaderData,
|
|
214
|
+
actionData: context.actionData,
|
|
215
|
+
errors: context.errors,
|
|
216
|
+
initialized: true,
|
|
217
|
+
navigation: router.IDLE_NAVIGATION,
|
|
218
|
+
restoreScrollPosition: null,
|
|
219
|
+
preventScrollReset: false,
|
|
220
|
+
revalidation: "idle",
|
|
221
|
+
fetchers: new Map(),
|
|
222
|
+
blockers: new Map()
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
get routes() {
|
|
227
|
+
return dataRoutes;
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
initialize() {
|
|
231
|
+
throw msg("initialize");
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
subscribe() {
|
|
235
|
+
throw msg("subscribe");
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
enableScrollRestoration() {
|
|
239
|
+
throw msg("enableScrollRestoration");
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
navigate() {
|
|
243
|
+
throw msg("navigate");
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
fetch() {
|
|
247
|
+
throw msg("fetch");
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
revalidate() {
|
|
251
|
+
throw msg("revalidate");
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
createHref,
|
|
255
|
+
encodeLocation,
|
|
256
|
+
|
|
257
|
+
getFetcher() {
|
|
258
|
+
return router.IDLE_FETCHER;
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
deleteFetcher() {
|
|
262
|
+
throw msg("deleteFetcher");
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
dispose() {
|
|
266
|
+
throw msg("dispose");
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
getBlocker() {
|
|
270
|
+
return router.IDLE_BLOCKER;
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
deleteBlocker() {
|
|
274
|
+
throw msg("deleteBlocker");
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
_internalFetchControllers: new Map(),
|
|
278
|
+
_internalActiveDeferreds: new Map(),
|
|
279
|
+
|
|
280
|
+
_internalSetRoutes() {
|
|
281
|
+
throw msg("_internalSetRoutes");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function createHref(to) {
|
|
288
|
+
return typeof to === "string" ? to : reactRouterDom.createPath(to);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function encodeLocation(to) {
|
|
292
|
+
// Locations should already be encoded on the server, so just return as-is
|
|
293
|
+
let path = typeof to === "string" ? reactRouterDom.parsePath(to) : to;
|
|
294
|
+
return {
|
|
295
|
+
pathname: path.pathname || "",
|
|
296
|
+
search: path.search || "",
|
|
297
|
+
hash: path.hash || ""
|
|
298
|
+
};
|
|
299
|
+
} // This utility is based on https://github.com/zertosh/htmlescape
|
|
300
|
+
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
const ESCAPE_LOOKUP = {
|
|
304
|
+
"&": "\\u0026",
|
|
305
|
+
">": "\\u003e",
|
|
306
|
+
"<": "\\u003c",
|
|
307
|
+
"\u2028": "\\u2028",
|
|
308
|
+
"\u2029": "\\u2029"
|
|
309
|
+
};
|
|
310
|
+
const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
311
|
+
|
|
312
|
+
function htmlEscape(str) {
|
|
313
|
+
return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
exports.StaticRouter = StaticRouter;
|
|
317
|
+
exports.StaticRouterProvider = StaticRouterProvider;
|
|
318
|
+
exports.createStaticHandler = createStaticHandler;
|
|
319
|
+
exports.createStaticRouter = createStaticRouter;
|
package/server.mjs
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Action, UNSAFE_invariant, isRouteErrorResponse, createStaticHandler as createStaticHandler$1, UNSAFE_convertRoutesToDataRoutes, IDLE_NAVIGATION, IDLE_FETCHER, IDLE_BLOCKER } from '@remix-run/router';
|
|
3
|
+
import { UNSAFE_useRoutesImpl, UNSAFE_mapRouteProperties } from 'react-router';
|
|
4
|
+
import { parsePath, Router, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, createPath } from 'react-router-dom';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A <Router> that may not navigate to any other location. This is useful
|
|
8
|
+
* on the server where there is no stateful UI.
|
|
9
|
+
*/
|
|
10
|
+
function StaticRouter({
|
|
11
|
+
basename,
|
|
12
|
+
children,
|
|
13
|
+
location: locationProp = "/"
|
|
14
|
+
}) {
|
|
15
|
+
if (typeof locationProp === "string") {
|
|
16
|
+
locationProp = parsePath(locationProp);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let action = Action.Pop;
|
|
20
|
+
let location = {
|
|
21
|
+
pathname: locationProp.pathname || "/",
|
|
22
|
+
search: locationProp.search || "",
|
|
23
|
+
hash: locationProp.hash || "",
|
|
24
|
+
state: locationProp.state || null,
|
|
25
|
+
key: locationProp.key || "default"
|
|
26
|
+
};
|
|
27
|
+
let staticNavigator = getStatelessNavigator();
|
|
28
|
+
return /*#__PURE__*/React.createElement(Router, {
|
|
29
|
+
basename: basename,
|
|
30
|
+
children: children,
|
|
31
|
+
location: location,
|
|
32
|
+
navigationType: action,
|
|
33
|
+
navigator: staticNavigator,
|
|
34
|
+
static: true
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A Data Router that may not navigate to any other location. This is useful
|
|
40
|
+
* on the server where there is no stateful UI.
|
|
41
|
+
*/
|
|
42
|
+
function StaticRouterProvider({
|
|
43
|
+
context,
|
|
44
|
+
router,
|
|
45
|
+
hydrate = true,
|
|
46
|
+
nonce
|
|
47
|
+
}) {
|
|
48
|
+
!(router && context) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : UNSAFE_invariant(false) : void 0;
|
|
49
|
+
let dataRouterContext = {
|
|
50
|
+
router,
|
|
51
|
+
navigator: getStatelessNavigator(),
|
|
52
|
+
static: true,
|
|
53
|
+
staticContext: context,
|
|
54
|
+
basename: context.basename || "/"
|
|
55
|
+
};
|
|
56
|
+
let hydrateScript = "";
|
|
57
|
+
|
|
58
|
+
if (hydrate !== false) {
|
|
59
|
+
let data = {
|
|
60
|
+
loaderData: context.loaderData,
|
|
61
|
+
actionData: context.actionData,
|
|
62
|
+
errors: serializeErrors(context.errors)
|
|
63
|
+
}; // Use JSON.parse here instead of embedding a raw JS object here to speed
|
|
64
|
+
// up parsing on the client. Dual-stringify is needed to ensure all quotes
|
|
65
|
+
// are properly escaped in the resulting string. See:
|
|
66
|
+
// https://v8.dev/blog/cost-of-javascript-2019#json
|
|
67
|
+
|
|
68
|
+
let json = htmlEscape(JSON.stringify(JSON.stringify(data)));
|
|
69
|
+
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let {
|
|
73
|
+
state
|
|
74
|
+
} = dataRouterContext.router;
|
|
75
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UNSAFE_DataRouterContext.Provider, {
|
|
76
|
+
value: dataRouterContext
|
|
77
|
+
}, /*#__PURE__*/React.createElement(UNSAFE_DataRouterStateContext.Provider, {
|
|
78
|
+
value: state
|
|
79
|
+
}, /*#__PURE__*/React.createElement(Router, {
|
|
80
|
+
basename: dataRouterContext.basename,
|
|
81
|
+
location: state.location,
|
|
82
|
+
navigationType: state.historyAction,
|
|
83
|
+
navigator: dataRouterContext.navigator,
|
|
84
|
+
static: dataRouterContext.static
|
|
85
|
+
}, /*#__PURE__*/React.createElement(DataRoutes, {
|
|
86
|
+
routes: router.routes,
|
|
87
|
+
state: state
|
|
88
|
+
})))), hydrateScript ? /*#__PURE__*/React.createElement("script", {
|
|
89
|
+
suppressHydrationWarning: true,
|
|
90
|
+
nonce: nonce,
|
|
91
|
+
dangerouslySetInnerHTML: {
|
|
92
|
+
__html: hydrateScript
|
|
93
|
+
}
|
|
94
|
+
}) : null);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function DataRoutes({
|
|
98
|
+
routes,
|
|
99
|
+
state
|
|
100
|
+
}) {
|
|
101
|
+
return UNSAFE_useRoutesImpl(routes, undefined, state);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function serializeErrors(errors) {
|
|
105
|
+
if (!errors) return null;
|
|
106
|
+
let entries = Object.entries(errors);
|
|
107
|
+
let serialized = {};
|
|
108
|
+
|
|
109
|
+
for (let [key, val] of entries) {
|
|
110
|
+
// Hey you! If you change this, please change the corresponding logic in
|
|
111
|
+
// deserializeErrors in react-router-dom/index.tsx :)
|
|
112
|
+
if (isRouteErrorResponse(val)) {
|
|
113
|
+
serialized[key] = { ...val,
|
|
114
|
+
__type: "RouteErrorResponse"
|
|
115
|
+
};
|
|
116
|
+
} else if (val instanceof Error) {
|
|
117
|
+
// Do not serialize stack traces from SSR for security reasons
|
|
118
|
+
serialized[key] = {
|
|
119
|
+
message: val.message,
|
|
120
|
+
__type: "Error"
|
|
121
|
+
};
|
|
122
|
+
} else {
|
|
123
|
+
serialized[key] = val;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return serialized;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getStatelessNavigator() {
|
|
131
|
+
return {
|
|
132
|
+
createHref,
|
|
133
|
+
encodeLocation,
|
|
134
|
+
|
|
135
|
+
push(to) {
|
|
136
|
+
throw new Error(`You cannot use navigator.push() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)})\` somewhere in your app.`);
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
replace(to) {
|
|
140
|
+
throw new Error(`You cannot use navigator.replace() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere ` + `in your app.`);
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
go(delta) {
|
|
144
|
+
throw new Error(`You cannot use navigator.go() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${delta})\` somewhere in your app.`);
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
back() {
|
|
148
|
+
throw new Error(`You cannot use navigator.back() on the server because it is a stateless ` + `environment.`);
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
forward() {
|
|
152
|
+
throw new Error(`You cannot use navigator.forward() on the server because it is a stateless ` + `environment.`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function createStaticHandler(routes, opts) {
|
|
159
|
+
return createStaticHandler$1(routes, { ...opts,
|
|
160
|
+
mapRouteProperties: UNSAFE_mapRouteProperties
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function createStaticRouter(routes, context) {
|
|
164
|
+
let manifest = {};
|
|
165
|
+
let dataRoutes = UNSAFE_convertRoutesToDataRoutes(routes, UNSAFE_mapRouteProperties, undefined, manifest); // Because our context matches may be from a framework-agnostic set of
|
|
166
|
+
// routes passed to createStaticHandler(), we update them here with our
|
|
167
|
+
// newly created/enhanced data routes
|
|
168
|
+
|
|
169
|
+
let matches = context.matches.map(match => {
|
|
170
|
+
let route = manifest[match.route.id] || match.route;
|
|
171
|
+
return { ...match,
|
|
172
|
+
route
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
let msg = method => `You cannot use router.${method}() on the server because it is a stateless environment`;
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
get basename() {
|
|
180
|
+
return context.basename;
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
get state() {
|
|
184
|
+
return {
|
|
185
|
+
historyAction: Action.Pop,
|
|
186
|
+
location: context.location,
|
|
187
|
+
matches,
|
|
188
|
+
loaderData: context.loaderData,
|
|
189
|
+
actionData: context.actionData,
|
|
190
|
+
errors: context.errors,
|
|
191
|
+
initialized: true,
|
|
192
|
+
navigation: IDLE_NAVIGATION,
|
|
193
|
+
restoreScrollPosition: null,
|
|
194
|
+
preventScrollReset: false,
|
|
195
|
+
revalidation: "idle",
|
|
196
|
+
fetchers: new Map(),
|
|
197
|
+
blockers: new Map()
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
get routes() {
|
|
202
|
+
return dataRoutes;
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
initialize() {
|
|
206
|
+
throw msg("initialize");
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
subscribe() {
|
|
210
|
+
throw msg("subscribe");
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
enableScrollRestoration() {
|
|
214
|
+
throw msg("enableScrollRestoration");
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
navigate() {
|
|
218
|
+
throw msg("navigate");
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
fetch() {
|
|
222
|
+
throw msg("fetch");
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
revalidate() {
|
|
226
|
+
throw msg("revalidate");
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
createHref,
|
|
230
|
+
encodeLocation,
|
|
231
|
+
|
|
232
|
+
getFetcher() {
|
|
233
|
+
return IDLE_FETCHER;
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
deleteFetcher() {
|
|
237
|
+
throw msg("deleteFetcher");
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
dispose() {
|
|
241
|
+
throw msg("dispose");
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
getBlocker() {
|
|
245
|
+
return IDLE_BLOCKER;
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
deleteBlocker() {
|
|
249
|
+
throw msg("deleteBlocker");
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
_internalFetchControllers: new Map(),
|
|
253
|
+
_internalActiveDeferreds: new Map(),
|
|
254
|
+
|
|
255
|
+
_internalSetRoutes() {
|
|
256
|
+
throw msg("_internalSetRoutes");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function createHref(to) {
|
|
263
|
+
return typeof to === "string" ? to : createPath(to);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function encodeLocation(to) {
|
|
267
|
+
// Locations should already be encoded on the server, so just return as-is
|
|
268
|
+
let path = typeof to === "string" ? parsePath(to) : to;
|
|
269
|
+
return {
|
|
270
|
+
pathname: path.pathname || "",
|
|
271
|
+
search: path.search || "",
|
|
272
|
+
hash: path.hash || ""
|
|
273
|
+
};
|
|
274
|
+
} // This utility is based on https://github.com/zertosh/htmlescape
|
|
275
|
+
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
const ESCAPE_LOOKUP = {
|
|
279
|
+
"&": "\\u0026",
|
|
280
|
+
">": "\\u003e",
|
|
281
|
+
"<": "\\u003c",
|
|
282
|
+
"\u2028": "\\u2028",
|
|
283
|
+
"\u2029": "\\u2029"
|
|
284
|
+
};
|
|
285
|
+
const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
286
|
+
|
|
287
|
+
function htmlEscape(str) {
|
|
288
|
+
return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export { StaticRouter, StaticRouterProvider, createStaticHandler, createStaticRouter };
|
package/BrowserRouter.js
DELETED
package/HashRouter.js
DELETED
package/Link.js
DELETED
package/MemoryRouter.js
DELETED
package/NavLink.js
DELETED
package/Prompt.js
DELETED
package/Redirect.js
DELETED
package/Route.js
DELETED
package/Router.js
DELETED
package/StaticRouter.js
DELETED
package/Switch.js
DELETED