@remix-run/router 1.2.0 → 1.2.1-pre.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 +6 -0
- package/dist/router.cjs.js +60 -27
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +60 -27
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +60 -27
- 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/package.json +1 -1
- package/router.ts +50 -18
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -1092,7 +1092,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1092
1092
|
replace =
|
|
1093
1093
|
result.location === state.location.pathname + state.location.search;
|
|
1094
1094
|
}
|
|
1095
|
-
await startRedirectNavigation(state, result, replace);
|
|
1095
|
+
await startRedirectNavigation(state, result, { submission, replace });
|
|
1096
1096
|
return { shortCircuited: true };
|
|
1097
1097
|
}
|
|
1098
1098
|
|
|
@@ -1152,10 +1152,26 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1152
1152
|
loadingNavigation = navigation;
|
|
1153
1153
|
}
|
|
1154
1154
|
|
|
1155
|
+
// If this was a redirect from an action we don't have a "submission" but
|
|
1156
|
+
// we have it on the loading navigation so use that if available
|
|
1157
|
+
let activeSubmission = submission
|
|
1158
|
+
? submission
|
|
1159
|
+
: loadingNavigation.formMethod &&
|
|
1160
|
+
loadingNavigation.formAction &&
|
|
1161
|
+
loadingNavigation.formData &&
|
|
1162
|
+
loadingNavigation.formEncType
|
|
1163
|
+
? {
|
|
1164
|
+
formMethod: loadingNavigation.formMethod,
|
|
1165
|
+
formAction: loadingNavigation.formAction,
|
|
1166
|
+
formData: loadingNavigation.formData,
|
|
1167
|
+
formEncType: loadingNavigation.formEncType,
|
|
1168
|
+
}
|
|
1169
|
+
: undefined;
|
|
1170
|
+
|
|
1155
1171
|
let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(
|
|
1156
1172
|
state,
|
|
1157
1173
|
matches,
|
|
1158
|
-
|
|
1174
|
+
activeSubmission,
|
|
1159
1175
|
location,
|
|
1160
1176
|
isRevalidationRequired,
|
|
1161
1177
|
cancelledDeferredRoutes,
|
|
@@ -1244,7 +1260,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1244
1260
|
// If any loaders returned a redirect Response, start a new REPLACE navigation
|
|
1245
1261
|
let redirect = findRedirect(results);
|
|
1246
1262
|
if (redirect) {
|
|
1247
|
-
await startRedirectNavigation(state, redirect, replace);
|
|
1263
|
+
await startRedirectNavigation(state, redirect, { replace });
|
|
1248
1264
|
return { shortCircuited: true };
|
|
1249
1265
|
}
|
|
1250
1266
|
|
|
@@ -1401,7 +1417,10 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1401
1417
|
state.fetchers.set(key, loadingFetcher);
|
|
1402
1418
|
updateState({ fetchers: new Map(state.fetchers) });
|
|
1403
1419
|
|
|
1404
|
-
return startRedirectNavigation(state, actionResult,
|
|
1420
|
+
return startRedirectNavigation(state, actionResult, {
|
|
1421
|
+
submission,
|
|
1422
|
+
isFetchActionRedirect: true,
|
|
1423
|
+
});
|
|
1405
1424
|
}
|
|
1406
1425
|
|
|
1407
1426
|
// Process any non-redirect errors thrown
|
|
@@ -1495,7 +1514,7 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1495
1514
|
|
|
1496
1515
|
let redirect = findRedirect(results);
|
|
1497
1516
|
if (redirect) {
|
|
1498
|
-
return startRedirectNavigation(state, redirect);
|
|
1517
|
+
return startRedirectNavigation(state, redirect, { submission });
|
|
1499
1518
|
}
|
|
1500
1519
|
|
|
1501
1520
|
// Process and commit output from loaders
|
|
@@ -1673,8 +1692,15 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1673
1692
|
async function startRedirectNavigation(
|
|
1674
1693
|
state: RouterState,
|
|
1675
1694
|
redirect: RedirectResult,
|
|
1676
|
-
|
|
1677
|
-
|
|
1695
|
+
{
|
|
1696
|
+
submission,
|
|
1697
|
+
replace,
|
|
1698
|
+
isFetchActionRedirect,
|
|
1699
|
+
}: {
|
|
1700
|
+
submission?: Submission;
|
|
1701
|
+
replace?: boolean;
|
|
1702
|
+
isFetchActionRedirect?: boolean;
|
|
1703
|
+
} = {}
|
|
1678
1704
|
) {
|
|
1679
1705
|
if (redirect.revalidate) {
|
|
1680
1706
|
isRevalidationRequired = true;
|
|
@@ -1714,24 +1740,30 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1714
1740
|
let redirectHistoryAction =
|
|
1715
1741
|
replace === true ? HistoryAction.Replace : HistoryAction.Push;
|
|
1716
1742
|
|
|
1743
|
+
// Use the incoming submission if provided, fallback on the active one in
|
|
1744
|
+
// state.navigation
|
|
1717
1745
|
let { formMethod, formAction, formEncType, formData } = state.navigation;
|
|
1746
|
+
if (!submission && formMethod && formAction && formData && formEncType) {
|
|
1747
|
+
submission = {
|
|
1748
|
+
formMethod,
|
|
1749
|
+
formAction,
|
|
1750
|
+
formEncType,
|
|
1751
|
+
formData,
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1718
1754
|
|
|
1719
1755
|
// If this was a 307/308 submission we want to preserve the HTTP method and
|
|
1720
1756
|
// re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the
|
|
1721
1757
|
// redirected location
|
|
1722
1758
|
if (
|
|
1723
1759
|
redirectPreserveMethodStatusCodes.has(redirect.status) &&
|
|
1724
|
-
|
|
1725
|
-
isMutationMethod(formMethod)
|
|
1726
|
-
formEncType &&
|
|
1727
|
-
formData
|
|
1760
|
+
submission &&
|
|
1761
|
+
isMutationMethod(submission.formMethod)
|
|
1728
1762
|
) {
|
|
1729
1763
|
await startNavigation(redirectHistoryAction, redirectLocation, {
|
|
1730
1764
|
submission: {
|
|
1731
|
-
|
|
1765
|
+
...submission,
|
|
1732
1766
|
formAction: redirect.location,
|
|
1733
|
-
formEncType,
|
|
1734
|
-
formData,
|
|
1735
1767
|
},
|
|
1736
1768
|
});
|
|
1737
1769
|
} else {
|
|
@@ -1741,10 +1773,10 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1741
1773
|
overrideNavigation: {
|
|
1742
1774
|
state: "loading",
|
|
1743
1775
|
location: redirectLocation,
|
|
1744
|
-
formMethod: formMethod
|
|
1745
|
-
formAction: formAction
|
|
1746
|
-
formEncType: formEncType
|
|
1747
|
-
formData: formData
|
|
1776
|
+
formMethod: submission ? submission.formMethod : undefined,
|
|
1777
|
+
formAction: submission ? submission.formAction : undefined,
|
|
1778
|
+
formEncType: submission ? submission.formEncType : undefined,
|
|
1779
|
+
formData: submission ? submission.formData : undefined,
|
|
1748
1780
|
},
|
|
1749
1781
|
});
|
|
1750
1782
|
}
|