react-router-dom 6.4.0-pre.3 → 6.4.0-pre.6
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 +20 -0
- package/LICENSE.md +22 -0
- package/dist/dom.d.ts +68 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +812 -0
- package/dist/index.js.map +1 -0
- package/dist/main.js +19 -0
- package/dist/react-router-dom.development.js +757 -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 +23 -0
- package/dist/server.js +125 -0
- package/dist/server.mjs +101 -0
- package/dist/umd/react-router-dom.development.js +1029 -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 +25 -16
- package/server.d.ts +23 -0
- package/server.js +125 -0
- package/server.mjs +101 -0
- package/.eslintrc +0 -12
- package/__tests__/DataBrowserRouter-test.tsx +0 -2199
- package/__tests__/custom-environment.js +0 -19
- package/__tests__/data-static-router-test.tsx +0 -194
- package/__tests__/exports-test.tsx +0 -10
- package/__tests__/link-click-test.tsx +0 -255
- package/__tests__/link-href-test.tsx +0 -547
- package/__tests__/link-push-test.tsx +0 -225
- package/__tests__/nav-link-active-test.tsx +0 -626
- package/__tests__/navigate-encode-params-test.tsx +0 -96
- package/__tests__/search-params-test.tsx +0 -69
- package/__tests__/setup.ts +0 -15
- package/__tests__/static-link-test.tsx +0 -36
- package/__tests__/static-location-test.tsx +0 -60
- package/__tests__/static-navigate-test.tsx +0 -32
- package/__tests__/useLinkClickHandler-test.tsx +0 -202
- package/dom.ts +0 -240
- package/index.tsx +0 -1009
- package/jest-transformer.js +0 -10
- package/jest.config.js +0 -10
- package/node-main.js +0 -7
- package/server.tsx +0 -148
- package/tsconfig.json +0 -20
package/server.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Action, createRouter, createMemoryHistory, invariant } from '@remix-run/router';
|
|
3
|
+
import { parsePath, Router, createRoutesFromChildren, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, Routes, createPath } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A <Router> that may not navigate to any other location. This is useful
|
|
7
|
+
* on the server where there is no stateful UI.
|
|
8
|
+
*/
|
|
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
|
+
* A Data Router that may not navigate to any other location. This is useful
|
|
39
|
+
* on the server where there is no stateful UI.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
function DataStaticRouter({
|
|
43
|
+
data,
|
|
44
|
+
location = "/",
|
|
45
|
+
children
|
|
46
|
+
}) {
|
|
47
|
+
// Create a router but do not call initialize() so it has no side effects
|
|
48
|
+
// and performs no data fetching
|
|
49
|
+
let staticRouter = createRouter({
|
|
50
|
+
history: createMemoryHistory({
|
|
51
|
+
initialEntries: [location]
|
|
52
|
+
}),
|
|
53
|
+
routes: createRoutesFromChildren(children),
|
|
54
|
+
hydrationData: data
|
|
55
|
+
});
|
|
56
|
+
!staticRouter.state.initialized ? process.env.NODE_ENV !== "production" ? invariant(false, "You must provide a complete `data` prop for <DataStaticRouter>") : invariant(false) : void 0;
|
|
57
|
+
let staticNavigator = getStatelessNavigator();
|
|
58
|
+
return /*#__PURE__*/React.createElement(UNSAFE_DataRouterContext.Provider, {
|
|
59
|
+
value: staticRouter
|
|
60
|
+
}, /*#__PURE__*/React.createElement(UNSAFE_DataRouterStateContext.Provider, {
|
|
61
|
+
value: staticRouter.state
|
|
62
|
+
}, /*#__PURE__*/React.createElement(Router, {
|
|
63
|
+
location: staticRouter.state.location,
|
|
64
|
+
navigationType: staticRouter.state.historyAction,
|
|
65
|
+
navigator: staticNavigator,
|
|
66
|
+
static: true
|
|
67
|
+
}, /*#__PURE__*/React.createElement(Routes, {
|
|
68
|
+
children: children
|
|
69
|
+
}))));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getStatelessNavigator() {
|
|
73
|
+
return {
|
|
74
|
+
createHref(to) {
|
|
75
|
+
return typeof to === "string" ? to : createPath(to);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
push(to) {
|
|
79
|
+
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.`);
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
replace(to) {
|
|
83
|
+
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.`);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
go(delta) {
|
|
87
|
+
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.`);
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
back() {
|
|
91
|
+
throw new Error(`You cannot use navigator.back() on the server because it is a stateless ` + `environment.`);
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
forward() {
|
|
95
|
+
throw new Error(`You cannot use navigator.forward() on the server because it is a stateless ` + `environment.`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { DataStaticRouter, StaticRouter };
|