clear-react-router 1.0.19 → 1.0.20
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/dist/index.d.ts +1 -0
- package/dist/index.js +54 -15
- package/dist/utils/redirect.d.ts +7 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export { useBeforeUnload } from './hooks/useBeforeUnload';
|
|
|
9
9
|
export { useRouterContext } from './hooks/useRouterContext';
|
|
10
10
|
export { createRouter } from './utils/utils';
|
|
11
11
|
export { redirect } from './utils/redirect';
|
|
12
|
+
export type { RouteItem, BlockerState } from './types/global';
|
package/dist/index.js
CHANGED
|
@@ -128,8 +128,58 @@ 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
|
|
131
182
|
//#region hooks/useHandleNavigation.ts
|
|
132
|
-
var isRedirect = (error) => typeof error === "object" && error !== null && error.cause === "redirect";
|
|
133
183
|
var useHandleNavigation = ({ setLocation, routeList, context, revalidateCache }) => {
|
|
134
184
|
const [blockedRoute, setBlockedRoute] = useState({
|
|
135
185
|
from: "",
|
|
@@ -147,10 +197,9 @@ var useHandleNavigation = ({ setLocation, routeList, context, revalidateCache })
|
|
|
147
197
|
}
|
|
148
198
|
await revalidateCache(nextItem);
|
|
149
199
|
if (nextItem?.afterLoad) await nextItem?.afterLoad(context);
|
|
150
|
-
} catch (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
history.replaceState(null, "", redirect.url);
|
|
200
|
+
} catch (redirect) {
|
|
201
|
+
if (!(redirect instanceof Redirect)) return redirect;
|
|
202
|
+
history.replaceState(null, "", `${redirect.url}${redirect.search || ""}`);
|
|
154
203
|
setLocation({
|
|
155
204
|
pathname: redirect.url,
|
|
156
205
|
search: redirect.search
|
|
@@ -425,14 +474,4 @@ var useRouterContext = () => {
|
|
|
425
474
|
};
|
|
426
475
|
};
|
|
427
476
|
//#endregion
|
|
428
|
-
//#region utils/redirect.ts
|
|
429
|
-
var redirect = (url, search) => {
|
|
430
|
-
const error = /* @__PURE__ */ new Error();
|
|
431
|
-
error.cause = "redirect";
|
|
432
|
-
throw Object.assign(error, {
|
|
433
|
-
url,
|
|
434
|
-
search: search || ""
|
|
435
|
-
});
|
|
436
|
-
};
|
|
437
|
-
//#endregion
|
|
438
477
|
export { Link, Router, createRouter, redirect, useBeforeUnload, useBlocker, useLoaderState, useLocation, useNavigate, useParams, useRouterContext };
|
package/dist/utils/redirect.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare class Redirect {
|
|
2
|
+
url: string;
|
|
3
|
+
search?: string;
|
|
4
|
+
cause: 'redirect';
|
|
5
|
+
constructor(url: string, search?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const redirect: (url: string, search?: string) => Promise<never>;
|