@remix-run/router 1.7.2 → 1.8.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/CHANGELOG.md +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/router.cjs.js +102 -43
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +42 -13
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +102 -43
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/history.ts +11 -0
- package/index.ts +1 -0
- package/package.json +2 -2
- package/router.ts +23 -10
- package/utils.ts +12 -0
package/dist/router.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.
|
|
2
|
+
* @remix-run/router v1.8.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -204,6 +204,15 @@ function createHashHistory(options) {
|
|
|
204
204
|
search = "",
|
|
205
205
|
hash = ""
|
|
206
206
|
} = parsePath(window.location.hash.substr(1));
|
|
207
|
+
// Hash URL should always have a leading / just like window.location.pathname
|
|
208
|
+
// does, so if an app ends up at a route like /#something then we add a
|
|
209
|
+
// leading slash so all of our path-matching behaves the same as if it would
|
|
210
|
+
// in a browser router. This is particularly important when there exists a
|
|
211
|
+
// root splat route (<Route path="*">) since that matches internally against
|
|
212
|
+
// "/*" and we'd expect /#something to 404 in a hash router app.
|
|
213
|
+
if (!pathname.startsWith("/") && !pathname.startsWith(".")) {
|
|
214
|
+
pathname = "/" + pathname;
|
|
215
|
+
}
|
|
207
216
|
return createLocation("", {
|
|
208
217
|
pathname,
|
|
209
218
|
search,
|
|
@@ -1167,6 +1176,16 @@ const redirect = function redirect(url, init) {
|
|
|
1167
1176
|
headers
|
|
1168
1177
|
}));
|
|
1169
1178
|
};
|
|
1179
|
+
/**
|
|
1180
|
+
* A redirect response that will force a document reload to the new location.
|
|
1181
|
+
* Sets the status code and the `Location` header.
|
|
1182
|
+
* Defaults to "302 Found".
|
|
1183
|
+
*/
|
|
1184
|
+
const redirectDocument = (url, init) => {
|
|
1185
|
+
let response = redirect(url, init);
|
|
1186
|
+
response.headers.set("X-Remix-Reload-Document", "true");
|
|
1187
|
+
return response;
|
|
1188
|
+
};
|
|
1170
1189
|
/**
|
|
1171
1190
|
* @private
|
|
1172
1191
|
* Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
|
|
@@ -2246,11 +2265,20 @@ function createRouter(init) {
|
|
|
2246
2265
|
_isFetchActionRedirect: true
|
|
2247
2266
|
} : {}));
|
|
2248
2267
|
invariant(redirectLocation, "Expected a location on the redirect navigation");
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2268
|
+
if (isBrowser) {
|
|
2269
|
+
let isDocumentReload = false;
|
|
2270
|
+
if (redirect.reloadDocument) {
|
|
2271
|
+
// Hard reload if the response contained X-Remix-Reload-Document
|
|
2272
|
+
isDocumentReload = true;
|
|
2273
|
+
} else if (ABSOLUTE_URL_REGEX.test(redirect.location)) {
|
|
2274
|
+
const url = init.history.createURL(redirect.location);
|
|
2275
|
+
isDocumentReload =
|
|
2276
|
+
// Hard reload if it's an absolute URL to a new origin
|
|
2277
|
+
url.origin !== routerWindow.location.origin ||
|
|
2278
|
+
// Hard reload if it's an absolute URL that does not match our basename
|
|
2279
|
+
stripBasename(url.pathname, basename) == null;
|
|
2280
|
+
}
|
|
2281
|
+
if (isDocumentReload) {
|
|
2254
2282
|
if (replace) {
|
|
2255
2283
|
routerWindow.location.replace(redirect.location);
|
|
2256
2284
|
} else {
|
|
@@ -2757,7 +2785,7 @@ function createStaticHandler(routes, opts) {
|
|
|
2757
2785
|
// it to bail out and then return or throw here based on whether the user
|
|
2758
2786
|
// returned or threw
|
|
2759
2787
|
if (isQueryRouteResponse(e)) {
|
|
2760
|
-
if (e.type === ResultType.error
|
|
2788
|
+
if (e.type === ResultType.error) {
|
|
2761
2789
|
throw e.response;
|
|
2762
2790
|
}
|
|
2763
2791
|
return e.response;
|
|
@@ -3417,18 +3445,19 @@ async function callLoaderOrAction(type, request, match, matches, manifest, mapRo
|
|
|
3417
3445
|
type: ResultType.redirect,
|
|
3418
3446
|
status,
|
|
3419
3447
|
location,
|
|
3420
|
-
revalidate: result.headers.get("X-Remix-Revalidate") !== null
|
|
3448
|
+
revalidate: result.headers.get("X-Remix-Revalidate") !== null,
|
|
3449
|
+
reloadDocument: result.headers.get("X-Remix-Reload-Document") !== null
|
|
3421
3450
|
};
|
|
3422
3451
|
}
|
|
3423
3452
|
// For SSR single-route requests, we want to hand Responses back directly
|
|
3424
3453
|
// without unwrapping. We do this with the QueryRouteResponse wrapper
|
|
3425
3454
|
// interface so we can know whether it was returned or thrown
|
|
3426
3455
|
if (opts.isRouteRequest) {
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
type: resultType || ResultType.data,
|
|
3456
|
+
let queryRouteResponse = {
|
|
3457
|
+
type: resultType === ResultType.error ? ResultType.error : ResultType.data,
|
|
3430
3458
|
response: result
|
|
3431
3459
|
};
|
|
3460
|
+
throw queryRouteResponse;
|
|
3432
3461
|
}
|
|
3433
3462
|
let data;
|
|
3434
3463
|
let contentType = result.headers.get("Content-Type");
|
|
@@ -3774,7 +3803,7 @@ function isRedirectResponse(result) {
|
|
|
3774
3803
|
return status >= 300 && status <= 399 && location != null;
|
|
3775
3804
|
}
|
|
3776
3805
|
function isQueryRouteResponse(obj) {
|
|
3777
|
-
return obj && isResponse(obj.response) && (obj.type === ResultType.data || ResultType.error);
|
|
3806
|
+
return obj && isResponse(obj.response) && (obj.type === ResultType.data || obj.type === ResultType.error);
|
|
3778
3807
|
}
|
|
3779
3808
|
function isValidMethod(method) {
|
|
3780
3809
|
return validRequestMethods.has(method.toLowerCase());
|
|
@@ -4005,5 +4034,5 @@ function getDoneFetcher(data) {
|
|
|
4005
4034
|
}
|
|
4006
4035
|
//#endregion
|
|
4007
4036
|
|
|
4008
|
-
export { AbortedDeferredError, Action, ErrorResponse, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, UNSAFE_DEFERRED_SYMBOL, DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, invariant as UNSAFE_invariant, warning as UNSAFE_warning, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, createRouter, createStaticHandler, defer, generatePath, getStaticContextFromError, getToPathname, isDeferredData, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, parsePath, redirect, resolvePath, resolveTo, stripBasename };
|
|
4037
|
+
export { AbortedDeferredError, Action, ErrorResponse, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, UNSAFE_DEFERRED_SYMBOL, DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, invariant as UNSAFE_invariant, warning as UNSAFE_warning, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, createRouter, createStaticHandler, defer, generatePath, getStaticContextFromError, getToPathname, isDeferredData, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, parsePath, redirect, redirectDocument, resolvePath, resolveTo, stripBasename };
|
|
4009
4038
|
//# sourceMappingURL=router.js.map
|