@aminnairi/react-router 3.0.2 → 4.0.0
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/README.md +31 -0
- package/dist/index.js +41 -377
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Type-safe router for the React library
|
|
|
26
26
|
- [Transition](#transition)
|
|
27
27
|
- [Error handling](#error-handling)
|
|
28
28
|
- [License](#license)
|
|
29
|
+
- [Contributing](../CONTRIBUTING.md)
|
|
29
30
|
- [Changelogs](#changelogs)
|
|
30
31
|
- [Versions](#versions)
|
|
31
32
|
- [3.0.0](#300)
|
|
@@ -935,6 +936,8 @@ See [`LICENSE`](./LICENSE).
|
|
|
935
936
|
|
|
936
937
|
### Versions
|
|
937
938
|
|
|
939
|
+
- [`4.0.0`](#400)
|
|
940
|
+
- [`3.0.2`](#302)
|
|
938
941
|
- [`3.0.1`](#301)
|
|
939
942
|
- [`3.0.0`](#300)
|
|
940
943
|
- [`2.1.0`](#210)
|
|
@@ -946,6 +949,34 @@ See [`LICENSE`](./LICENSE).
|
|
|
946
949
|
- [`0.1.1`](#011)
|
|
947
950
|
- [`0.1.0`](#010)
|
|
948
951
|
|
|
952
|
+
### 4.0.0
|
|
953
|
+
|
|
954
|
+
#### Major changes
|
|
955
|
+
|
|
956
|
+
- Externalized React from the build output to prevent hooks mismatch issues with consumer applications. Consumers are now required to have React as a dependency in their project.
|
|
957
|
+
|
|
958
|
+
#### Minor changes
|
|
959
|
+
|
|
960
|
+
- Explicitly set the build output format to ESM.
|
|
961
|
+
|
|
962
|
+
#### Bug & security fixes
|
|
963
|
+
|
|
964
|
+
- Fixed lint error in the source code dependencies.
|
|
965
|
+
|
|
966
|
+
### 3.0.2
|
|
967
|
+
|
|
968
|
+
#### Major changes
|
|
969
|
+
|
|
970
|
+
None.
|
|
971
|
+
|
|
972
|
+
#### Minor changes
|
|
973
|
+
|
|
974
|
+
None.
|
|
975
|
+
|
|
976
|
+
#### Bug & security fixes
|
|
977
|
+
|
|
978
|
+
- Fixed the output file path in the rolldown configuration (changed from `dist/index.ts` to `dist/index.js`)
|
|
979
|
+
|
|
949
980
|
### 3.0.1
|
|
950
981
|
|
|
951
982
|
#### Major changes
|
package/dist/index.js
CHANGED
|
@@ -1,379 +1,43 @@
|
|
|
1
|
+
import { Component, createContext, useCallback, useContext, useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
1
2
|
//#region \0rolldown/runtime.js
|
|
2
3
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3
4
|
//#endregion
|
|
4
|
-
//#region ../../node_modules/react/cjs/react.production.
|
|
5
|
+
//#region ../../node_modules/react/cjs/react-jsx-runtime.production.js
|
|
5
6
|
/**
|
|
6
7
|
* @license React
|
|
7
|
-
* react.production.
|
|
8
|
+
* react-jsx-runtime.production.js
|
|
8
9
|
*
|
|
9
|
-
* Copyright (c)
|
|
10
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
11
|
*
|
|
11
12
|
* This source code is licensed under the MIT license found in the
|
|
12
13
|
* LICENSE file in the root directory of this source tree.
|
|
13
14
|
*/
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
enqueueForceUpdate: function() {},
|
|
26
|
-
enqueueReplaceState: function() {},
|
|
27
|
-
enqueueSetState: function() {}
|
|
28
|
-
}, C = Object.assign, D = {};
|
|
29
|
-
function E(a, b, e) {
|
|
30
|
-
this.props = a;
|
|
31
|
-
this.context = b;
|
|
32
|
-
this.refs = D;
|
|
33
|
-
this.updater = e || B;
|
|
34
|
-
}
|
|
35
|
-
E.prototype.isReactComponent = {};
|
|
36
|
-
E.prototype.setState = function(a, b) {
|
|
37
|
-
if ("object" !== typeof a && "function" !== typeof a && null != a) throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
|
|
38
|
-
this.updater.enqueueSetState(this, a, b, "setState");
|
|
39
|
-
};
|
|
40
|
-
E.prototype.forceUpdate = function(a) {
|
|
41
|
-
this.updater.enqueueForceUpdate(this, a, "forceUpdate");
|
|
42
|
-
};
|
|
43
|
-
function F() {}
|
|
44
|
-
F.prototype = E.prototype;
|
|
45
|
-
function G(a, b, e) {
|
|
46
|
-
this.props = a;
|
|
47
|
-
this.context = b;
|
|
48
|
-
this.refs = D;
|
|
49
|
-
this.updater = e || B;
|
|
50
|
-
}
|
|
51
|
-
var H = G.prototype = new F();
|
|
52
|
-
H.constructor = G;
|
|
53
|
-
C(H, E.prototype);
|
|
54
|
-
H.isPureReactComponent = !0;
|
|
55
|
-
var I = Array.isArray, J = Object.prototype.hasOwnProperty, K = { current: null }, L = {
|
|
56
|
-
key: !0,
|
|
57
|
-
ref: !0,
|
|
58
|
-
__self: !0,
|
|
59
|
-
__source: !0
|
|
60
|
-
};
|
|
61
|
-
function M(a, b, e) {
|
|
62
|
-
var d, c = {}, k = null, h = null;
|
|
63
|
-
if (null != b) for (d in void 0 !== b.ref && (h = b.ref), void 0 !== b.key && (k = "" + b.key), b) J.call(b, d) && !L.hasOwnProperty(d) && (c[d] = b[d]);
|
|
64
|
-
var g = arguments.length - 2;
|
|
65
|
-
if (1 === g) c.children = e;
|
|
66
|
-
else if (1 < g) {
|
|
67
|
-
for (var f = Array(g), m = 0; m < g; m++) f[m] = arguments[m + 2];
|
|
68
|
-
c.children = f;
|
|
69
|
-
}
|
|
70
|
-
if (a && a.defaultProps) for (d in g = a.defaultProps, g) void 0 === c[d] && (c[d] = g[d]);
|
|
15
|
+
var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
16
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
|
|
17
|
+
function jsxProd(type, config, maybeKey) {
|
|
18
|
+
var key = null;
|
|
19
|
+
void 0 !== maybeKey && (key = "" + maybeKey);
|
|
20
|
+
void 0 !== config.key && (key = "" + config.key);
|
|
21
|
+
if ("key" in config) {
|
|
22
|
+
maybeKey = {};
|
|
23
|
+
for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
|
|
24
|
+
} else maybeKey = config;
|
|
25
|
+
config = maybeKey.ref;
|
|
71
26
|
return {
|
|
72
|
-
$$typeof:
|
|
73
|
-
type
|
|
74
|
-
key
|
|
75
|
-
ref:
|
|
76
|
-
props:
|
|
77
|
-
_owner: K.current
|
|
27
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
28
|
+
type,
|
|
29
|
+
key,
|
|
30
|
+
ref: void 0 !== config ? config : null,
|
|
31
|
+
props: maybeKey
|
|
78
32
|
};
|
|
79
33
|
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
$$typeof: l,
|
|
83
|
-
type: a.type,
|
|
84
|
-
key: b,
|
|
85
|
-
ref: a.ref,
|
|
86
|
-
props: a.props,
|
|
87
|
-
_owner: a._owner
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function O(a) {
|
|
91
|
-
return "object" === typeof a && null !== a && a.$$typeof === l;
|
|
92
|
-
}
|
|
93
|
-
function escape(a) {
|
|
94
|
-
var b = {
|
|
95
|
-
"=": "=0",
|
|
96
|
-
":": "=2"
|
|
97
|
-
};
|
|
98
|
-
return "$" + a.replace(/[=:]/g, function(a) {
|
|
99
|
-
return b[a];
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
var P = /\/+/g;
|
|
103
|
-
function Q(a, b) {
|
|
104
|
-
return "object" === typeof a && null !== a && null != a.key ? escape("" + a.key) : b.toString(36);
|
|
105
|
-
}
|
|
106
|
-
function R(a, b, e, d, c) {
|
|
107
|
-
var k = typeof a;
|
|
108
|
-
if ("undefined" === k || "boolean" === k) a = null;
|
|
109
|
-
var h = !1;
|
|
110
|
-
if (null === a) h = !0;
|
|
111
|
-
else switch (k) {
|
|
112
|
-
case "string":
|
|
113
|
-
case "number":
|
|
114
|
-
h = !0;
|
|
115
|
-
break;
|
|
116
|
-
case "object": switch (a.$$typeof) {
|
|
117
|
-
case l:
|
|
118
|
-
case n: h = !0;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (h) return h = a, c = c(h), a = "" === d ? "." + Q(h, 0) : d, I(c) ? (e = "", null != a && (e = a.replace(P, "$&/") + "/"), R(c, b, e, "", function(a) {
|
|
122
|
-
return a;
|
|
123
|
-
})) : null != c && (O(c) && (c = N(c, e + (!c.key || h && h.key === c.key ? "" : ("" + c.key).replace(P, "$&/") + "/") + a)), b.push(c)), 1;
|
|
124
|
-
h = 0;
|
|
125
|
-
d = "" === d ? "." : d + ":";
|
|
126
|
-
if (I(a)) for (var g = 0; g < a.length; g++) {
|
|
127
|
-
k = a[g];
|
|
128
|
-
var f = d + Q(k, g);
|
|
129
|
-
h += R(k, b, e, f, c);
|
|
130
|
-
}
|
|
131
|
-
else if (f = A(a), "function" === typeof f) for (a = f.call(a), g = 0; !(k = a.next()).done;) k = k.value, f = d + Q(k, g++), h += R(k, b, e, f, c);
|
|
132
|
-
else if ("object" === k) throw b = String(a), Error("Objects are not valid as a React child (found: " + ("[object Object]" === b ? "object with keys {" + Object.keys(a).join(", ") + "}" : b) + "). If you meant to render a collection of children, use an array instead.");
|
|
133
|
-
return h;
|
|
134
|
-
}
|
|
135
|
-
function S(a, b, e) {
|
|
136
|
-
if (null == a) return a;
|
|
137
|
-
var d = [], c = 0;
|
|
138
|
-
R(a, d, "", "", function(a) {
|
|
139
|
-
return b.call(e, a, c++);
|
|
140
|
-
});
|
|
141
|
-
return d;
|
|
142
|
-
}
|
|
143
|
-
function T(a) {
|
|
144
|
-
if (-1 === a._status) {
|
|
145
|
-
var b = a._result;
|
|
146
|
-
b = b();
|
|
147
|
-
b.then(function(b) {
|
|
148
|
-
if (0 === a._status || -1 === a._status) a._status = 1, a._result = b;
|
|
149
|
-
}, function(b) {
|
|
150
|
-
if (0 === a._status || -1 === a._status) a._status = 2, a._result = b;
|
|
151
|
-
});
|
|
152
|
-
-1 === a._status && (a._status = 0, a._result = b);
|
|
153
|
-
}
|
|
154
|
-
if (1 === a._status) return a._result.default;
|
|
155
|
-
throw a._result;
|
|
156
|
-
}
|
|
157
|
-
var U = { current: null }, V = { transition: null }, W = {
|
|
158
|
-
ReactCurrentDispatcher: U,
|
|
159
|
-
ReactCurrentBatchConfig: V,
|
|
160
|
-
ReactCurrentOwner: K
|
|
161
|
-
};
|
|
162
|
-
function X() {
|
|
163
|
-
throw Error("act(...) is not supported in production builds of React.");
|
|
164
|
-
}
|
|
165
|
-
exports.Children = {
|
|
166
|
-
map: S,
|
|
167
|
-
forEach: function(a, b, e) {
|
|
168
|
-
S(a, function() {
|
|
169
|
-
b.apply(this, arguments);
|
|
170
|
-
}, e);
|
|
171
|
-
},
|
|
172
|
-
count: function(a) {
|
|
173
|
-
var b = 0;
|
|
174
|
-
S(a, function() {
|
|
175
|
-
b++;
|
|
176
|
-
});
|
|
177
|
-
return b;
|
|
178
|
-
},
|
|
179
|
-
toArray: function(a) {
|
|
180
|
-
return S(a, function(a) {
|
|
181
|
-
return a;
|
|
182
|
-
}) || [];
|
|
183
|
-
},
|
|
184
|
-
only: function(a) {
|
|
185
|
-
if (!O(a)) throw Error("React.Children.only expected to receive a single React element child.");
|
|
186
|
-
return a;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
exports.Component = E;
|
|
190
|
-
exports.Fragment = p;
|
|
191
|
-
exports.Profiler = r;
|
|
192
|
-
exports.PureComponent = G;
|
|
193
|
-
exports.StrictMode = q;
|
|
194
|
-
exports.Suspense = w;
|
|
195
|
-
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = W;
|
|
196
|
-
exports.act = X;
|
|
197
|
-
exports.cloneElement = function(a, b, e) {
|
|
198
|
-
if (null === a || void 0 === a) throw Error("React.cloneElement(...): The argument must be a React element, but you passed " + a + ".");
|
|
199
|
-
var d = C({}, a.props), c = a.key, k = a.ref, h = a._owner;
|
|
200
|
-
if (null != b) {
|
|
201
|
-
void 0 !== b.ref && (k = b.ref, h = K.current);
|
|
202
|
-
void 0 !== b.key && (c = "" + b.key);
|
|
203
|
-
if (a.type && a.type.defaultProps) var g = a.type.defaultProps;
|
|
204
|
-
for (f in b) J.call(b, f) && !L.hasOwnProperty(f) && (d[f] = void 0 === b[f] && void 0 !== g ? g[f] : b[f]);
|
|
205
|
-
}
|
|
206
|
-
var f = arguments.length - 2;
|
|
207
|
-
if (1 === f) d.children = e;
|
|
208
|
-
else if (1 < f) {
|
|
209
|
-
g = Array(f);
|
|
210
|
-
for (var m = 0; m < f; m++) g[m] = arguments[m + 2];
|
|
211
|
-
d.children = g;
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
$$typeof: l,
|
|
215
|
-
type: a.type,
|
|
216
|
-
key: c,
|
|
217
|
-
ref: k,
|
|
218
|
-
props: d,
|
|
219
|
-
_owner: h
|
|
220
|
-
};
|
|
221
|
-
};
|
|
222
|
-
exports.createContext = function(a) {
|
|
223
|
-
a = {
|
|
224
|
-
$$typeof: u,
|
|
225
|
-
_currentValue: a,
|
|
226
|
-
_currentValue2: a,
|
|
227
|
-
_threadCount: 0,
|
|
228
|
-
Provider: null,
|
|
229
|
-
Consumer: null,
|
|
230
|
-
_defaultValue: null,
|
|
231
|
-
_globalName: null
|
|
232
|
-
};
|
|
233
|
-
a.Provider = {
|
|
234
|
-
$$typeof: t,
|
|
235
|
-
_context: a
|
|
236
|
-
};
|
|
237
|
-
return a.Consumer = a;
|
|
238
|
-
};
|
|
239
|
-
exports.createElement = M;
|
|
240
|
-
exports.createFactory = function(a) {
|
|
241
|
-
var b = M.bind(null, a);
|
|
242
|
-
b.type = a;
|
|
243
|
-
return b;
|
|
244
|
-
};
|
|
245
|
-
exports.createRef = function() {
|
|
246
|
-
return { current: null };
|
|
247
|
-
};
|
|
248
|
-
exports.forwardRef = function(a) {
|
|
249
|
-
return {
|
|
250
|
-
$$typeof: v,
|
|
251
|
-
render: a
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
exports.isValidElement = O;
|
|
255
|
-
exports.lazy = function(a) {
|
|
256
|
-
return {
|
|
257
|
-
$$typeof: y,
|
|
258
|
-
_payload: {
|
|
259
|
-
_status: -1,
|
|
260
|
-
_result: a
|
|
261
|
-
},
|
|
262
|
-
_init: T
|
|
263
|
-
};
|
|
264
|
-
};
|
|
265
|
-
exports.memo = function(a, b) {
|
|
266
|
-
return {
|
|
267
|
-
$$typeof: x,
|
|
268
|
-
type: a,
|
|
269
|
-
compare: void 0 === b ? null : b
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
exports.startTransition = function(a) {
|
|
273
|
-
var b = V.transition;
|
|
274
|
-
V.transition = {};
|
|
275
|
-
try {
|
|
276
|
-
a();
|
|
277
|
-
} finally {
|
|
278
|
-
V.transition = b;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
exports.unstable_act = X;
|
|
282
|
-
exports.useCallback = function(a, b) {
|
|
283
|
-
return U.current.useCallback(a, b);
|
|
284
|
-
};
|
|
285
|
-
exports.useContext = function(a) {
|
|
286
|
-
return U.current.useContext(a);
|
|
287
|
-
};
|
|
288
|
-
exports.useDebugValue = function() {};
|
|
289
|
-
exports.useDeferredValue = function(a) {
|
|
290
|
-
return U.current.useDeferredValue(a);
|
|
291
|
-
};
|
|
292
|
-
exports.useEffect = function(a, b) {
|
|
293
|
-
return U.current.useEffect(a, b);
|
|
294
|
-
};
|
|
295
|
-
exports.useId = function() {
|
|
296
|
-
return U.current.useId();
|
|
297
|
-
};
|
|
298
|
-
exports.useImperativeHandle = function(a, b, e) {
|
|
299
|
-
return U.current.useImperativeHandle(a, b, e);
|
|
300
|
-
};
|
|
301
|
-
exports.useInsertionEffect = function(a, b) {
|
|
302
|
-
return U.current.useInsertionEffect(a, b);
|
|
303
|
-
};
|
|
304
|
-
exports.useLayoutEffect = function(a, b) {
|
|
305
|
-
return U.current.useLayoutEffect(a, b);
|
|
306
|
-
};
|
|
307
|
-
exports.useMemo = function(a, b) {
|
|
308
|
-
return U.current.useMemo(a, b);
|
|
309
|
-
};
|
|
310
|
-
exports.useReducer = function(a, b, e) {
|
|
311
|
-
return U.current.useReducer(a, b, e);
|
|
312
|
-
};
|
|
313
|
-
exports.useRef = function(a) {
|
|
314
|
-
return U.current.useRef(a);
|
|
315
|
-
};
|
|
316
|
-
exports.useState = function(a) {
|
|
317
|
-
return U.current.useState(a);
|
|
318
|
-
};
|
|
319
|
-
exports.useSyncExternalStore = function(a, b, e) {
|
|
320
|
-
return U.current.useSyncExternalStore(a, b, e);
|
|
321
|
-
};
|
|
322
|
-
exports.useTransition = function() {
|
|
323
|
-
return U.current.useTransition();
|
|
324
|
-
};
|
|
325
|
-
exports.version = "18.3.1";
|
|
326
|
-
}));
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region ../../node_modules/react/index.js
|
|
329
|
-
var require_react = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
330
|
-
module.exports = require_react_production_min();
|
|
331
|
-
}));
|
|
332
|
-
//#endregion
|
|
333
|
-
//#region ../../node_modules/react/cjs/react-jsx-runtime.production.min.js
|
|
334
|
-
/**
|
|
335
|
-
* @license React
|
|
336
|
-
* react-jsx-runtime.production.min.js
|
|
337
|
-
*
|
|
338
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
339
|
-
*
|
|
340
|
-
* This source code is licensed under the MIT license found in the
|
|
341
|
-
* LICENSE file in the root directory of this source tree.
|
|
342
|
-
*/
|
|
343
|
-
var require_react_jsx_runtime_production_min = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
344
|
-
var f = require_react(), k = Symbol.for("react.element"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = {
|
|
345
|
-
key: !0,
|
|
346
|
-
ref: !0,
|
|
347
|
-
__self: !0,
|
|
348
|
-
__source: !0
|
|
349
|
-
};
|
|
350
|
-
function q(c, a, g) {
|
|
351
|
-
var b, d = {}, e = null, h = null;
|
|
352
|
-
void 0 !== g && (e = "" + g);
|
|
353
|
-
void 0 !== a.key && (e = "" + a.key);
|
|
354
|
-
void 0 !== a.ref && (h = a.ref);
|
|
355
|
-
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
356
|
-
if (c && c.defaultProps) for (b in a = c.defaultProps, a) void 0 === d[b] && (d[b] = a[b]);
|
|
357
|
-
return {
|
|
358
|
-
$$typeof: k,
|
|
359
|
-
type: c,
|
|
360
|
-
key: e,
|
|
361
|
-
ref: h,
|
|
362
|
-
props: d,
|
|
363
|
-
_owner: n.current
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
exports.jsx = q;
|
|
367
|
-
}));
|
|
368
|
-
//#endregion
|
|
369
|
-
//#region ../../node_modules/react/jsx-runtime.js
|
|
370
|
-
var require_jsx_runtime = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
371
|
-
module.exports = require_react_jsx_runtime_production_min();
|
|
34
|
+
exports.jsx = jsxProd;
|
|
372
35
|
}));
|
|
373
36
|
//#endregion
|
|
374
37
|
//#region index.tsx
|
|
375
|
-
var
|
|
376
|
-
|
|
38
|
+
var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
39
|
+
module.exports = require_react_jsx_runtime_production();
|
|
40
|
+
})))();
|
|
377
41
|
function normalize(uri) {
|
|
378
42
|
return uri.trim().toLowerCase().replace(/\/+/g, "/").replace(/^\/+|\/$/g, "");
|
|
379
43
|
}
|
|
@@ -419,7 +83,7 @@ var Uri = class Uri {
|
|
|
419
83
|
].join("/"), null, null);
|
|
420
84
|
}
|
|
421
85
|
};
|
|
422
|
-
var ErrorBoundary = class extends
|
|
86
|
+
var ErrorBoundary = class extends Component {
|
|
423
87
|
constructor(props) {
|
|
424
88
|
super(props);
|
|
425
89
|
this.state = {
|
|
@@ -550,7 +214,7 @@ const slideVerticalTransition = async (direction, next) => {
|
|
|
550
214
|
}
|
|
551
215
|
};
|
|
552
216
|
function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallback, issue: Issue, transition }) {
|
|
553
|
-
const RouterContext =
|
|
217
|
+
const RouterContext = createContext({
|
|
554
218
|
locale: null,
|
|
555
219
|
prefix: null,
|
|
556
220
|
path: "/",
|
|
@@ -561,7 +225,7 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
561
225
|
return matchPath(page.path, path);
|
|
562
226
|
}
|
|
563
227
|
function useLocale() {
|
|
564
|
-
const context =
|
|
228
|
+
const context = useContext(RouterContext);
|
|
565
229
|
if (!context) throw new Error("component using the useLocale hook has not been wrapped inside RouterProvider.");
|
|
566
230
|
return {
|
|
567
231
|
locale: context.locale,
|
|
@@ -573,19 +237,19 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
573
237
|
};
|
|
574
238
|
}
|
|
575
239
|
function usePrefix() {
|
|
576
|
-
const context =
|
|
240
|
+
const context = useContext(RouterContext);
|
|
577
241
|
if (!context) throw new Error("Component using the usePrefix hook has not been wrapped inside RouterProvider");
|
|
578
242
|
return { prefix: context.prefix };
|
|
579
243
|
}
|
|
580
244
|
function usePath() {
|
|
581
|
-
const context =
|
|
245
|
+
const context = useContext(RouterContext);
|
|
582
246
|
if (!context) throw new Error("Component using the usePath hook has not been wrapped inside RouterProvider");
|
|
583
247
|
return { path: context.path };
|
|
584
248
|
}
|
|
585
249
|
function useNavigateToPage(page) {
|
|
586
250
|
const { locale } = useLocale();
|
|
587
251
|
const { prefix } = usePrefix();
|
|
588
|
-
return
|
|
252
|
+
return useCallback((...[params]) => {
|
|
589
253
|
const path = Object.entries(params ?? {}).reduce((oldParams, [name, value]) => {
|
|
590
254
|
return oldParams.replace(`:${name}`, String(value));
|
|
591
255
|
}, page.path);
|
|
@@ -600,14 +264,14 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
600
264
|
]);
|
|
601
265
|
}
|
|
602
266
|
function RouterProvider({ children }) {
|
|
603
|
-
const uri =
|
|
604
|
-
const [locale, setLocale] =
|
|
605
|
-
const [path, setPath] =
|
|
606
|
-
const [prefix, setPrefix] =
|
|
267
|
+
const uri = useMemo(() => Uri.from(window.location.pathname, expectedPrefix, locales), []);
|
|
268
|
+
const [locale, setLocale] = useState(uri.locale);
|
|
269
|
+
const [path, setPath] = useState(uri.path);
|
|
270
|
+
const [prefix, setPrefix] = useState(uri.prefix);
|
|
607
271
|
function setHash(newHash) {
|
|
608
272
|
window.location.hash = newHash;
|
|
609
273
|
}
|
|
610
|
-
const value =
|
|
274
|
+
const value = useMemo(() => {
|
|
611
275
|
return {
|
|
612
276
|
locale,
|
|
613
277
|
path,
|
|
@@ -620,7 +284,7 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
620
284
|
prefix,
|
|
621
285
|
path
|
|
622
286
|
]);
|
|
623
|
-
const onNavigation =
|
|
287
|
+
const onNavigation = useEffectEvent((direction) => {
|
|
624
288
|
const pathname = normalize(window.location.pathname);
|
|
625
289
|
const uri = Uri.from(pathname, expectedPrefix, locales);
|
|
626
290
|
const defaultTransition = (_, next) => {
|
|
@@ -632,7 +296,7 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
632
296
|
setPrefix(uri.prefix);
|
|
633
297
|
});
|
|
634
298
|
});
|
|
635
|
-
const onMount =
|
|
299
|
+
const onMount = useEffectEvent(() => {
|
|
636
300
|
const pathname = `/${normalize(window.location.pathname)}`;
|
|
637
301
|
const uri = Uri.from(pathname, expectedPrefix, [locale, ...locales ?? []]);
|
|
638
302
|
const newPathname = `/${normalize(`${uri.prefix ?? expectedPrefix ?? ""}/${uri.locale ?? locales?.at(0) ?? ""}/${uri.path}`)}`;
|
|
@@ -641,7 +305,7 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
641
305
|
window.dispatchEvent(new Event("pushstate"));
|
|
642
306
|
}
|
|
643
307
|
});
|
|
644
|
-
|
|
308
|
+
useEffect(() => {
|
|
645
309
|
const abortController = new AbortController();
|
|
646
310
|
window.addEventListener("pushstate", () => {
|
|
647
311
|
onNavigation("forward");
|
|
@@ -653,7 +317,7 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
653
317
|
return () => {
|
|
654
318
|
abortController.abort();
|
|
655
319
|
};
|
|
656
|
-
}, []);
|
|
320
|
+
}, [onMount, onNavigation]);
|
|
657
321
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterContext.Provider, {
|
|
658
322
|
value,
|
|
659
323
|
children
|
|
@@ -661,11 +325,11 @@ function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallba
|
|
|
661
325
|
}
|
|
662
326
|
function RouterView() {
|
|
663
327
|
const { path } = usePath();
|
|
664
|
-
const foundPage =
|
|
328
|
+
const foundPage = useMemo(() => {
|
|
665
329
|
return pages.find((page) => {
|
|
666
330
|
return matchPath(page.path, path);
|
|
667
331
|
});
|
|
668
|
-
}, [path
|
|
332
|
+
}, [path]);
|
|
669
333
|
if (foundPage) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
|
|
670
334
|
issue: Issue,
|
|
671
335
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(foundPage.element, { parameters: matchParameters(foundPage.path, path) })
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@aminnairi/react-router",
|
|
4
4
|
"description": "Type-safe router for the React library",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "4.0.0",
|
|
6
6
|
"homepage": "https://github.com/aminnairi/react-router",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -32,13 +32,14 @@
|
|
|
32
32
|
"history"
|
|
33
33
|
],
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react": "
|
|
35
|
+
"react": "^19.2.4"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
39
39
|
"build": "tsc && rolldown --config rolldown.config.ts"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@types/react": "^19.2.14",
|
|
42
43
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
43
44
|
"@typescript-eslint/parser": "^7.2.0",
|
|
44
45
|
"eslint": "^8.57.0",
|