clear-react-router 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +59 -59
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -128,58 +128,8 @@ var useLatest = (value) => {
128
128
  return ref;
129
129
  };
130
130
  //#endregion
131
- //#region \0@oxc-project+runtime@0.132.0/helpers/typeof.js
132
- function _typeof(o) {
133
- "@babel/helpers - typeof";
134
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
135
- return typeof o;
136
- } : function(o) {
137
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
138
- }, _typeof(o);
139
- }
140
- //#endregion
141
- //#region \0@oxc-project+runtime@0.132.0/helpers/toPrimitive.js
142
- function toPrimitive(t, r) {
143
- if ("object" != _typeof(t) || !t) return t;
144
- var e = t[Symbol.toPrimitive];
145
- if (void 0 !== e) {
146
- var i = e.call(t, r || "default");
147
- if ("object" != _typeof(i)) return i;
148
- throw new TypeError("@@toPrimitive must return a primitive value.");
149
- }
150
- return ("string" === r ? String : Number)(t);
151
- }
152
- //#endregion
153
- //#region \0@oxc-project+runtime@0.132.0/helpers/toPropertyKey.js
154
- function toPropertyKey(t) {
155
- var i = toPrimitive(t, "string");
156
- return "symbol" == _typeof(i) ? i : i + "";
157
- }
158
- //#endregion
159
- //#region \0@oxc-project+runtime@0.132.0/helpers/defineProperty.js
160
- function _defineProperty(e, r, t) {
161
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
162
- value: t,
163
- enumerable: !0,
164
- configurable: !0,
165
- writable: !0
166
- }) : e[r] = t, e;
167
- }
168
- //#endregion
169
- //#region utils/redirect.ts
170
- var Redirect = class {
171
- constructor(url, search) {
172
- _defineProperty(this, "url", void 0);
173
- _defineProperty(this, "search", void 0);
174
- _defineProperty(this, "cause", void 0);
175
- this.url = url;
176
- this.search = search;
177
- this.cause = "redirect";
178
- }
179
- };
180
- var redirect = (url, search) => Promise.reject(new Redirect(url, search));
181
- //#endregion
182
131
  //#region hooks/useHandleNavigation.ts
132
+ var isRedirect = (error) => typeof error === "object" && error !== null && error.cause === "redirect";
183
133
  var useHandleNavigation = ({ setLocation, routeList, context, revalidateCache }) => {
184
134
  const [blockedRoute, setBlockedRoute] = useState({
185
135
  from: "",
@@ -191,15 +141,14 @@ var useHandleNavigation = ({ setLocation, routeList, context, revalidateCache })
191
141
  const nextItem = routeList.find((el) => comparePaths(el, nextLocation.pathname));
192
142
  if (nextItem?.beforeLoad) await nextItem?.beforeLoad(context);
193
143
  setLocation(nextLocation);
194
- if (nextLocation.pathname !== window.location.pathname) {
195
- history.pushState(null, "", nextLocation.pathname);
196
- prevPathname.current = nextLocation.pathname;
197
- }
144
+ prevPathname.current = nextLocation.pathname;
145
+ if (nextLocation.pathname !== window.location.pathname) history.pushState(null, "", nextLocation.pathname);
198
146
  await revalidateCache(nextItem, true);
199
147
  if (nextItem?.afterLoad) await nextItem?.afterLoad(context);
200
- } catch (redirect) {
201
- if (!(redirect instanceof Redirect)) return redirect;
202
- history.replaceState(null, "", `${redirect.url}${redirect.search || ""}`);
148
+ } catch (error) {
149
+ const redirect = error;
150
+ if (!isRedirect(redirect)) return redirect;
151
+ history.replaceState(null, "", redirect.url);
203
152
  setLocation({
204
153
  pathname: redirect.url,
205
154
  search: redirect.search
@@ -243,7 +192,7 @@ var useHandleNavigation = ({ setLocation, routeList, context, revalidateCache })
243
192
  from: prevPathname.current,
244
193
  to: newLocation.pathname
245
194
  });
246
- history.replaceState(null, "", prevPathname.current);
195
+ history.pushState(null, "", prevPathname.current);
247
196
  } else setNextLocationRef.current(newLocation);
248
197
  };
249
198
  window.addEventListener("popstate", handler);
@@ -466,4 +415,55 @@ var useRouterContext = () => {
466
415
  };
467
416
  };
468
417
  //#endregion
418
+ //#region \0@oxc-project+runtime@0.132.0/helpers/typeof.js
419
+ function _typeof(o) {
420
+ "@babel/helpers - typeof";
421
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
422
+ return typeof o;
423
+ } : function(o) {
424
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
425
+ }, _typeof(o);
426
+ }
427
+ //#endregion
428
+ //#region \0@oxc-project+runtime@0.132.0/helpers/toPrimitive.js
429
+ function toPrimitive(t, r) {
430
+ if ("object" != _typeof(t) || !t) return t;
431
+ var e = t[Symbol.toPrimitive];
432
+ if (void 0 !== e) {
433
+ var i = e.call(t, r || "default");
434
+ if ("object" != _typeof(i)) return i;
435
+ throw new TypeError("@@toPrimitive must return a primitive value.");
436
+ }
437
+ return ("string" === r ? String : Number)(t);
438
+ }
439
+ //#endregion
440
+ //#region \0@oxc-project+runtime@0.132.0/helpers/toPropertyKey.js
441
+ function toPropertyKey(t) {
442
+ var i = toPrimitive(t, "string");
443
+ return "symbol" == _typeof(i) ? i : i + "";
444
+ }
445
+ //#endregion
446
+ //#region \0@oxc-project+runtime@0.132.0/helpers/defineProperty.js
447
+ function _defineProperty(e, r, t) {
448
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
449
+ value: t,
450
+ enumerable: !0,
451
+ configurable: !0,
452
+ writable: !0
453
+ }) : e[r] = t, e;
454
+ }
455
+ //#endregion
456
+ //#region utils/redirect.ts
457
+ var Redirect = class {
458
+ constructor(url, search) {
459
+ _defineProperty(this, "url", void 0);
460
+ _defineProperty(this, "search", void 0);
461
+ _defineProperty(this, "cause", void 0);
462
+ this.url = url;
463
+ this.search = search;
464
+ this.cause = "redirect";
465
+ }
466
+ };
467
+ var redirect = (url, search) => Promise.reject(new Redirect(url, search));
468
+ //#endregion
469
469
  export { Link, Router, createRouter, redirect, useBeforeUnload, useBlocker, useLoaderState, useLocation, useNavigate, useParams, useRouterContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A lightweight, type-safe routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {