@remix-run/router 0.2.0-pre.9 → 1.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/CHANGELOG.md +8 -161
- package/README.md +24 -20
- package/dist/index.d.ts +1 -6
- package/dist/router.cjs.js +39 -88
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +51 -4
- package/dist/router.js +40 -86
- package/dist/router.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/index.ts +3 -37
- package/package.json +4 -1
- package/router.ts +79 -24
- package/utils.ts +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,167 +1,14 @@
|
|
|
1
1
|
# @remix-run/router
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 1.0.0
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This is the first stable release of `@remix-run/router`, which provides all the underlying routing and data loading/mutation logic for `react-router`. You should _not_ be using this package directly unless you are authoring a routing library similar to `react-router`.
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- fix: Await should fallback on route params navigations (#9181)
|
|
9
|
-
- fix: proxy defer resolve/reject values through tracked promises (#9200)
|
|
7
|
+
For an overview of the features provided by `react-router`, we recommend you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
For an overview of the features provided by `@remix-run/router`, please check out the [README][remix-router-readme].
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
- fix: fetcher submission revalidating fetchers using wrong key (#9166)
|
|
18
|
-
- fix: use a push navigation on submission errors (#9162)
|
|
19
|
-
|
|
20
|
-
## 0.2.0-pre.7
|
|
21
|
-
|
|
22
|
-
### Patch Changes
|
|
23
|
-
|
|
24
|
-
- fix: fix default redirect push/replace behavior (#9117)
|
|
25
|
-
|
|
26
|
-
## 0.2.0-pre.6
|
|
27
|
-
|
|
28
|
-
### Patch Changes
|
|
29
|
-
|
|
30
|
-
- fix: Rename `<Deferred>` to `<Await>` (#9095)
|
|
31
|
-
|
|
32
|
-
- We are no longer replacing the `Promise` on `loaderData` with the value/error
|
|
33
|
-
when it settles so it's now always a `Promise`.
|
|
34
|
-
- To that end, we changed from `<Deferred value={promise}>` to
|
|
35
|
-
`<Await resolve={promise}>` for clarity, and it also now supports using
|
|
36
|
-
`<Await>` with raw promises from anywhere, not only those on `loaderData`
|
|
37
|
-
from a defer() call.
|
|
38
|
-
- Note that raw promises will not be automatically cancelled on interruptions
|
|
39
|
-
so they are not recommended
|
|
40
|
-
- The hooks are now `useAsyncValue`/`useAsyncError`
|
|
41
|
-
|
|
42
|
-
## 0.2.0-pre.5
|
|
43
|
-
|
|
44
|
-
### Patch Changes
|
|
45
|
-
|
|
46
|
-
- feat: Deferred API Updates (#9070)
|
|
47
|
-
|
|
48
|
-
- Support array and single promise usages
|
|
49
|
-
- `return defer([ await critical(), lazy() ])`
|
|
50
|
-
- `return defer(lazy())`
|
|
51
|
-
- Remove `Deferrable`/`ResolvedDeferrable` in favor of raw `Promise`'s and `Awaited`
|
|
52
|
-
- Remove generics from `useAsyncValue` until `useLoaderData` generic is decided in 6.5
|
|
53
|
-
|
|
54
|
-
- feat: Add `createStaticRouter` for `@remix-run/router` SSR usage (#9013)
|
|
55
|
-
|
|
56
|
-
**Notable changes:**
|
|
57
|
-
|
|
58
|
-
- `request` is now the driving force inside the router utils, so that we can better handle `Request` instances coming form the server (as opposed to `string` and `Path` instances coming from the client)
|
|
59
|
-
- Removed the `signal` param from `loader` and `action` functions in favor of `request.signal`
|
|
60
|
-
|
|
61
|
-
**Example usage (Document Requests):**
|
|
62
|
-
|
|
63
|
-
```jsx
|
|
64
|
-
// Create a static handler
|
|
65
|
-
let { query } = unstable_createStaticHandler(routes);
|
|
66
|
-
|
|
67
|
-
// Perform a full-document query for the incoming Fetch Request. This will
|
|
68
|
-
// execute the appropriate action/loaders and return either the state or a
|
|
69
|
-
// Fetch Response in the case of redirects.
|
|
70
|
-
let state = await query(fetchRequest);
|
|
71
|
-
|
|
72
|
-
// If we received a Fetch Response back, let our server runtime handle directly
|
|
73
|
-
if (state instanceof Response) {
|
|
74
|
-
throw state;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Otherwise, render our application providing the data routes and state
|
|
78
|
-
let html = ReactDOMServer.renderToString(
|
|
79
|
-
<React.StrictMode>
|
|
80
|
-
<DataStaticRouter routes={routes} state={state} />
|
|
81
|
-
</React.StrictMode>
|
|
82
|
-
);
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**Example usage (Data Requests):**
|
|
86
|
-
|
|
87
|
-
```jsx
|
|
88
|
-
// Create a static route handler
|
|
89
|
-
let { queryRoute } = unstable_createStaticHandler(routes);
|
|
90
|
-
|
|
91
|
-
// Perform a single-route query for the incoming Fetch Request. This will
|
|
92
|
-
// execute the appropriate singular action/loader and return either the raw
|
|
93
|
-
// data or a Fetch Response
|
|
94
|
-
let data = await queryRoute(fetchRequest);
|
|
95
|
-
|
|
96
|
-
// If we received a Fetch Response back, return it directly
|
|
97
|
-
if (data instanceof Response) {
|
|
98
|
-
return data;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Otherwise, construct a Response from the raw data (assuming json here)
|
|
102
|
-
return new Response(JSON.stringify(data), {
|
|
103
|
-
headers: {
|
|
104
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
- feat: SSR Updates for React Router (#9058)
|
|
110
|
-
|
|
111
|
-
_Note: The Data-Router SSR aspects of `@remix-run/router` and `react-router-dom` are being released as **unstable** in this release (`unstable_createStaticHandler` and `unstable_DataStaticRouter`), and we plan to finalize them in a subsequent minor release once the kinks can be worked out with the Remix integration. To that end, they are available for use, but are subject to breaking changes in the next minor release._
|
|
112
|
-
|
|
113
|
-
- Remove `useRenderDataRouter()` in favor of `<DataRouterProvider>`/`<DataRouter>`
|
|
114
|
-
- Support automatic hydration in `<DataStaticRouter>`/`<DataBrowserRouter>`/`<DataHashRouter>`
|
|
115
|
-
- Uses `window.__staticRouterHydrationData`
|
|
116
|
-
- Can be disabled on the server via `<DataStaticRouter hydrate={false}>`
|
|
117
|
-
- Can be disabled (or overridden) in the browser by passing `hydrationData` to `<DataBrowserRouter>`/`<DataHashRouter>`
|
|
118
|
-
- `<DataStaticRouter>` now tracks it's own SSR error boundaries on `StaticHandlerContext`
|
|
119
|
-
- `StaticHandlerContext` now exposes `statusCode`/`loaderHeaders`/`actionHeaders`
|
|
120
|
-
- `foundMissingHydrationData` check removed since Remix routes may have loaders (for modules) that don't return data for `loaderData`
|
|
121
|
-
|
|
122
|
-
## 0.2.0-pre.4
|
|
123
|
-
|
|
124
|
-
### Patch Changes
|
|
125
|
-
|
|
126
|
-
- fix: Handle fetcher 404s as normal boundary errors (#9015)
|
|
127
|
-
- feat: adds `defer()` support to data routers (#9002)
|
|
128
|
-
- feat: add basename support for data routers (#9026)
|
|
129
|
-
- ci: simplify dist/ directory for CJS/ESM only (#9017)
|
|
130
|
-
- fix: Fix trailing slash behavior on pathless routing when using a basename (#9045)
|
|
131
|
-
|
|
132
|
-
## 0.2.0-pre.3
|
|
133
|
-
|
|
134
|
-
### Patch Changes
|
|
135
|
-
|
|
136
|
-
- fix: properly handle `<Form encType="multipart/form-data">` submissions (#8984)
|
|
137
|
-
- fix: Make path resolution trailing slash agnostic (#8861)
|
|
138
|
-
- fix: don't default to a `REPLACE` navigation on form submissions if the action redirected. The redirect takes care of avoiding the back-button-resubmit scenario, so by using a `PUSH` we allow the back button to go back to the pre-submission form page (#8979)
|
|
139
|
-
- fix: export ActionFunctionArgs/LoaderFunctionArgs up through router packages (#8975)
|
|
140
|
-
- fix: preserve loader data for loaders that opted out of revalidation (#8973)
|
|
141
|
-
|
|
142
|
-
[Full Changes](https://github.com/remix-run/react-router/compare/%40remix-run/router%400.2.0-pre.2...%40remix-run/router%400.2.0-pre.3)
|
|
143
|
-
|
|
144
|
-
## 0.2.0-pre.2
|
|
145
|
-
|
|
146
|
-
### Patch Changes
|
|
147
|
-
|
|
148
|
-
- Capture fetcher errors at contextual route error boundaries (#8945)
|
|
149
|
-
|
|
150
|
-
## 0.2.0-pre.1
|
|
151
|
-
|
|
152
|
-
### Patch Changes
|
|
153
|
-
|
|
154
|
-
- Fix missing `dist` files
|
|
155
|
-
|
|
156
|
-
## 0.2.0-pre.0
|
|
157
|
-
|
|
158
|
-
### Minor Changes
|
|
159
|
-
|
|
160
|
-
- Change `formMethod=GET` to be a loading navigation instead of submitting
|
|
161
|
-
|
|
162
|
-
### Patch Changes
|
|
163
|
-
|
|
164
|
-
- Make `fallbackElement` optional and change type to `ReactNode` (type changes only) (#8896)
|
|
165
|
-
- Properly trigger error boundaries on 404 routes
|
|
166
|
-
- Fix `resolveTo` so that it does not mutate the provided pathname (#8839)
|
|
167
|
-
- Pass fetcher `actionResult` through to `shouldRevalidate` on fetcher submissions
|
|
11
|
+
[rr-docs]: https://reactrouter.com/
|
|
12
|
+
[rr-feature-overview]: https://reactrouter.com/en/v6.4.0/start/overview
|
|
13
|
+
[rr-tutorial]: https://reactrouter.com/en/v6.4.0/start/tutorial
|
|
14
|
+
[remix-router-readme]: https://github.com/remix-run/react-router/blob/main/packages/router/README.md
|
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
# Router
|
|
1
|
+
# Remix Router
|
|
2
2
|
|
|
3
|
-
The `@remix-run/router` package is the heart of [React Router]
|
|
3
|
+
The `@remix-run/router` package is a framework-agnostic routing package (sometimes referred to as a browser-emulator) that serves as the heart of [React Router][react-router] and [Remix][remix] and provides all the core functionality for routing coupled with data loading and data mutations. It comes with built-in handling of errors, race-conditions, interruptions, cancellations, lazy-loading data, and much, much more.
|
|
4
4
|
|
|
5
|
-
If you're using React Router, you should never `import` anything directly from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
If you're using React Router, you should never `import` anything directly from the `@remix-run/router` or `react-router` packages, but you should have everything you need in either `react-router-dom` or `react-router-native`. Both of those packages re-export everything from `@remix-run/router` and `react-router`.
|
|
6
|
+
|
|
7
|
+
> **Warning**
|
|
8
|
+
>
|
|
9
|
+
> This router is a low-level package intended to be consumed by UI layer routing libraries. You should very likely not be using this package directly unless you are authoring a routing library such as [`react-router-dom`][react-router-repo] or one of it's other [UI ports][remix-routers-repo].
|
|
9
10
|
|
|
10
11
|
## API
|
|
11
12
|
|
|
@@ -15,12 +16,10 @@ A Router instance can be created using `createRouter`:
|
|
|
15
16
|
// Create and initialize a router. "initialize" contains all side effects
|
|
16
17
|
// including history listeners and kicking off the initial data fetch
|
|
17
18
|
let router = createRouter({
|
|
18
|
-
// Routes array
|
|
19
|
-
routes,
|
|
19
|
+
// Routes array
|
|
20
|
+
routes: ,
|
|
20
21
|
// History instance
|
|
21
22
|
history,
|
|
22
|
-
// Optional hydration data for SSR apps
|
|
23
|
-
hydrationData?: HydrationState;
|
|
24
23
|
}).initialize()
|
|
25
24
|
```
|
|
26
25
|
|
|
@@ -28,6 +27,8 @@ Internally, the Router represents the state in an object of the following format
|
|
|
28
27
|
|
|
29
28
|
```ts
|
|
30
29
|
interface RouterState {
|
|
30
|
+
// False during the initial data load, true once we have our initial data
|
|
31
|
+
initialized: boolean;
|
|
31
32
|
// The `history` action of the most recently completed navigation
|
|
32
33
|
historyAction: Action;
|
|
33
34
|
// The current location of the router. During a navigation this reflects
|
|
@@ -35,18 +36,10 @@ interface RouterState {
|
|
|
35
36
|
location: Location;
|
|
36
37
|
// The current set of route matches
|
|
37
38
|
matches: DataRouteMatch[];
|
|
38
|
-
// False during the initial data load, true once we have our initial data
|
|
39
|
-
initialized: boolean;
|
|
40
39
|
// The state of the current navigation
|
|
41
40
|
navigation: Navigation;
|
|
42
|
-
// The state of
|
|
41
|
+
// The state of any in-progress router.revalidate() calls
|
|
43
42
|
revalidation: RevalidationState;
|
|
44
|
-
// Scroll position to restore to for the active Location, false if we
|
|
45
|
-
// should not restore,m or null if we don't have a saved position
|
|
46
|
-
// Note: must be enabled via router.enableScrollRestoration()
|
|
47
|
-
restoreScrollPosition: number | false | null;
|
|
48
|
-
// Proxied `preventScrollReset` value passed to router.navigate() (default false)
|
|
49
|
-
preventScrollReset: boolean;
|
|
50
43
|
// Data from the loaders for the current matches
|
|
51
44
|
loaderData: RouteData;
|
|
52
45
|
// Data from the action for the current matches
|
|
@@ -55,6 +48,12 @@ interface RouterState {
|
|
|
55
48
|
errors: RouteData | null;
|
|
56
49
|
// Map of all active fetchers
|
|
57
50
|
fetchers: Map<string, Fetcher>;
|
|
51
|
+
// Scroll position to restore to for the active Location, false if we
|
|
52
|
+
// should not restore, or null if we don't have a saved position
|
|
53
|
+
// Note: must be enabled via router.enableScrollRestoration()
|
|
54
|
+
restoreScrollPosition: number | false | null;
|
|
55
|
+
// Proxied `preventScrollReset` value passed to router.navigate()
|
|
56
|
+
preventScrollReset: boolean;
|
|
58
57
|
}
|
|
59
58
|
```
|
|
60
59
|
|
|
@@ -98,6 +97,11 @@ router.fetch("key", "/page", {
|
|
|
98
97
|
});
|
|
99
98
|
```
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
### Revalidation
|
|
102
101
|
|
|
103
102
|
By default, active loaders will revalidate after any navigation or fetcher mutation. If you need to kick off a revalidation for other use-cases, you can use `router.revalidate()` to re-execute all active loaders.
|
|
103
|
+
|
|
104
|
+
[react-router]: https://reactrouter.com
|
|
105
|
+
[remix]: https://remix.run
|
|
106
|
+
[react-router-repo]: https://github.com/remix-run/react-router
|
|
107
|
+
[remix-routers-repo]: https://github.com/brophdawg11/remix-routers
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type { BrowserHistoryOptions, HashHistoryOptions, MemoryHistoryOptions } from "./history";
|
|
2
|
-
import type { Router, RouterInit } from "./router";
|
|
3
1
|
import { convertRoutesToDataRoutes } from "./utils";
|
|
4
2
|
export type { ActionFunction, ActionFunctionArgs, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils";
|
|
5
3
|
export { AbortedDeferredError, ErrorResponse, defer, generatePath, getToPathname, invariant, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils";
|
|
6
|
-
export type { BrowserHistory, HashHistory, History, InitialEntry, Location, MemoryHistory, Path, To, } from "./history";
|
|
4
|
+
export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
|
|
7
5
|
export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, parsePath, } from "./history";
|
|
8
6
|
export * from "./router";
|
|
9
|
-
export declare function createMemoryRouter({ initialEntries, initialIndex, ...routerInit }: MemoryHistoryOptions & Omit<RouterInit, "history">): Router;
|
|
10
|
-
export declare function createBrowserRouter({ window, ...routerInit }: BrowserHistoryOptions & Omit<RouterInit, "history">): Router;
|
|
11
|
-
export declare function createHashRouter({ window, ...routerInit }: HashHistoryOptions & Omit<RouterInit, "history">): Router;
|
|
12
7
|
/** @internal */
|
|
13
8
|
export { convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes };
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router
|
|
2
|
+
* @remix-run/router v1.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -29,21 +29,6 @@ function _extends() {
|
|
|
29
29
|
return _extends.apply(this, arguments);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
33
|
-
if (source == null) return {};
|
|
34
|
-
var target = {};
|
|
35
|
-
var sourceKeys = Object.keys(source);
|
|
36
|
-
var key, i;
|
|
37
|
-
|
|
38
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
39
|
-
key = sourceKeys[i];
|
|
40
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
41
|
-
target[key] = source[key];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return target;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
32
|
////////////////////////////////////////////////////////////////////////////////
|
|
48
33
|
//#region Types and Constants
|
|
49
34
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -701,9 +686,17 @@ function generatePath(path, params) {
|
|
|
701
686
|
return path.replace(/:(\w+)/g, (_, key) => {
|
|
702
687
|
invariant(params[key] != null, "Missing \":" + key + "\" param");
|
|
703
688
|
return params[key];
|
|
704
|
-
}).replace(
|
|
689
|
+
}).replace(/(\/?)\*/, (_, prefix, __, str) => {
|
|
705
690
|
const star = "*";
|
|
706
|
-
|
|
691
|
+
|
|
692
|
+
if (params[star] == null) {
|
|
693
|
+
// If no splat was provided, trim the trailing slash _unless_ it's
|
|
694
|
+
// the entire path
|
|
695
|
+
return str === "/*" ? "/" : "";
|
|
696
|
+
} // Apply the splat
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
return "" + prefix + params[star];
|
|
707
700
|
});
|
|
708
701
|
}
|
|
709
702
|
/**
|
|
@@ -1042,6 +1035,9 @@ class DeferredData {
|
|
|
1042
1035
|
|
|
1043
1036
|
if (this.controller.signal.aborted && error instanceof AbortedDeferredError) {
|
|
1044
1037
|
this.unlistenAbortSignal();
|
|
1038
|
+
Object.defineProperty(promise, "_error", {
|
|
1039
|
+
get: () => error
|
|
1040
|
+
});
|
|
1045
1041
|
return Promise.reject(error);
|
|
1046
1042
|
}
|
|
1047
1043
|
|
|
@@ -1222,9 +1218,9 @@ function createRouter(init) {
|
|
|
1222
1218
|
invariant(init.routes.length > 0, "You must provide a non-empty routes array to createRouter");
|
|
1223
1219
|
let dataRoutes = convertRoutesToDataRoutes(init.routes); // Cleanup function for history
|
|
1224
1220
|
|
|
1225
|
-
let unlistenHistory = null; // Externally-provided
|
|
1221
|
+
let unlistenHistory = null; // Externally-provided functions to call on all state changes
|
|
1226
1222
|
|
|
1227
|
-
let
|
|
1223
|
+
let subscribers = new Set(); // Externally-provided object to hold scroll restoration locations during routing
|
|
1228
1224
|
|
|
1229
1225
|
let savedScrollPositions = null; // Externally-provided function to get scroll restoration keys
|
|
1230
1226
|
|
|
@@ -1339,27 +1335,21 @@ function createRouter(init) {
|
|
|
1339
1335
|
unlistenHistory();
|
|
1340
1336
|
}
|
|
1341
1337
|
|
|
1342
|
-
|
|
1338
|
+
subscribers.clear();
|
|
1343
1339
|
(_pendingNavigationCon = pendingNavigationController) == null ? void 0 : _pendingNavigationCon.abort();
|
|
1344
1340
|
state.fetchers.forEach((_, key) => deleteFetcher(key));
|
|
1345
1341
|
} // Subscribe to state updates for the router
|
|
1346
1342
|
|
|
1347
1343
|
|
|
1348
1344
|
function subscribe(fn) {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
subscriber = fn;
|
|
1354
|
-
return () => {
|
|
1355
|
-
subscriber = null;
|
|
1356
|
-
};
|
|
1345
|
+
subscribers.add(fn);
|
|
1346
|
+
return () => subscribers.delete(fn);
|
|
1357
1347
|
} // Update our state and notify the calling context of the change
|
|
1358
1348
|
|
|
1359
1349
|
|
|
1360
1350
|
function updateState(newState) {
|
|
1361
1351
|
state = _extends({}, state, newState);
|
|
1362
|
-
subscriber
|
|
1352
|
+
subscribers.forEach(subscriber => subscriber(state));
|
|
1363
1353
|
} // Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION
|
|
1364
1354
|
// and setting state.[historyAction/location/matches] to the new route.
|
|
1365
1355
|
// - Location is a required param
|
|
@@ -2282,6 +2272,10 @@ function createRouter(init) {
|
|
|
2282
2272
|
}
|
|
2283
2273
|
|
|
2284
2274
|
router = {
|
|
2275
|
+
get basename() {
|
|
2276
|
+
return init.basename;
|
|
2277
|
+
},
|
|
2278
|
+
|
|
2285
2279
|
get state() {
|
|
2286
2280
|
return state;
|
|
2287
2281
|
},
|
|
@@ -2441,8 +2435,8 @@ function unstable_createStaticHandler(routes) {
|
|
|
2441
2435
|
errors: {
|
|
2442
2436
|
[boundaryMatch.route.id]: result.error
|
|
2443
2437
|
},
|
|
2444
|
-
// Note:
|
|
2445
|
-
//
|
|
2438
|
+
// Note: statusCode + headers are unused here since queryRoute will
|
|
2439
|
+
// return the raw Response or value
|
|
2446
2440
|
statusCode: 500,
|
|
2447
2441
|
loaderHeaders: {},
|
|
2448
2442
|
actionHeaders: {}
|
|
@@ -2456,13 +2450,11 @@ function unstable_createStaticHandler(routes) {
|
|
|
2456
2450
|
[actionMatch.route.id]: result.data
|
|
2457
2451
|
},
|
|
2458
2452
|
errors: null,
|
|
2459
|
-
// Note:
|
|
2460
|
-
// Response or value
|
|
2453
|
+
// Note: statusCode + headers are unused here since queryRoute will
|
|
2454
|
+
// return the raw Response or value
|
|
2461
2455
|
statusCode: 200,
|
|
2462
2456
|
loaderHeaders: {},
|
|
2463
|
-
actionHeaders:
|
|
2464
|
-
[actionMatch.route.id]: result.headers
|
|
2465
|
-
} : {})
|
|
2457
|
+
actionHeaders: {}
|
|
2466
2458
|
};
|
|
2467
2459
|
}
|
|
2468
2460
|
|
|
@@ -2477,7 +2469,9 @@ function unstable_createStaticHandler(routes) {
|
|
|
2477
2469
|
return _extends({}, context, {
|
|
2478
2470
|
statusCode: isRouteErrorResponse(result.error) ? result.error.status : 500,
|
|
2479
2471
|
actionData: null,
|
|
2480
|
-
actionHeaders: {}
|
|
2472
|
+
actionHeaders: _extends({}, result.headers ? {
|
|
2473
|
+
[actionMatch.route.id]: result.headers
|
|
2474
|
+
} : {})
|
|
2481
2475
|
});
|
|
2482
2476
|
}
|
|
2483
2477
|
|
|
@@ -2829,7 +2823,8 @@ async function callLoaderOrAction(type, request, match, skipRedirects, isRouteRe
|
|
|
2829
2823
|
if (resultType === ResultType.error) {
|
|
2830
2824
|
return {
|
|
2831
2825
|
type: resultType,
|
|
2832
|
-
error: new ErrorResponse(status, result.statusText, data)
|
|
2826
|
+
error: new ErrorResponse(status, result.statusText, data),
|
|
2827
|
+
headers: result.headers
|
|
2833
2828
|
};
|
|
2834
2829
|
}
|
|
2835
2830
|
|
|
@@ -2926,9 +2921,13 @@ function processRouteLoaderData(matches, matchesToLoad, results, pendingError, a
|
|
|
2926
2921
|
foundError = true;
|
|
2927
2922
|
statusCode = isRouteErrorResponse(result.error) ? result.error.status : 500;
|
|
2928
2923
|
}
|
|
2924
|
+
|
|
2925
|
+
if (result.headers) {
|
|
2926
|
+
loaderHeaders[id] = result.headers;
|
|
2927
|
+
}
|
|
2929
2928
|
} else if (isDeferredResult(result)) {
|
|
2930
2929
|
activeDeferreds == null ? void 0 : activeDeferreds.set(id, result.deferredData);
|
|
2931
|
-
loaderData[id] = result.deferredData.data;
|
|
2930
|
+
loaderData[id] = result.deferredData.data; // TODO: Add statusCode/headers once we wire up streaming in Remix
|
|
2932
2931
|
} else {
|
|
2933
2932
|
loaderData[id] = result.data; // Error status codes always override success status codes, but if all
|
|
2934
2933
|
// loaders are successful we take the deepest status code.
|
|
@@ -3174,62 +3173,14 @@ function createURL(location) {
|
|
|
3174
3173
|
return new URL(href, base);
|
|
3175
3174
|
} //#endregion
|
|
3176
3175
|
|
|
3177
|
-
const _excluded = ["initialEntries", "initialIndex"],
|
|
3178
|
-
_excluded2 = ["window"],
|
|
3179
|
-
_excluded3 = ["window"];
|
|
3180
|
-
function createMemoryRouter(_ref) {
|
|
3181
|
-
let {
|
|
3182
|
-
initialEntries,
|
|
3183
|
-
initialIndex
|
|
3184
|
-
} = _ref,
|
|
3185
|
-
routerInit = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
3186
|
-
|
|
3187
|
-
let history = createMemoryHistory({
|
|
3188
|
-
initialEntries,
|
|
3189
|
-
initialIndex
|
|
3190
|
-
});
|
|
3191
|
-
return createRouter(_extends({
|
|
3192
|
-
history
|
|
3193
|
-
}, routerInit));
|
|
3194
|
-
}
|
|
3195
|
-
function createBrowserRouter(_ref2) {
|
|
3196
|
-
let {
|
|
3197
|
-
window
|
|
3198
|
-
} = _ref2,
|
|
3199
|
-
routerInit = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
3200
|
-
|
|
3201
|
-
let history = createBrowserHistory({
|
|
3202
|
-
window
|
|
3203
|
-
});
|
|
3204
|
-
return createRouter(_extends({
|
|
3205
|
-
history
|
|
3206
|
-
}, routerInit));
|
|
3207
|
-
}
|
|
3208
|
-
function createHashRouter(_ref3) {
|
|
3209
|
-
let {
|
|
3210
|
-
window
|
|
3211
|
-
} = _ref3,
|
|
3212
|
-
routerInit = _objectWithoutPropertiesLoose(_ref3, _excluded3);
|
|
3213
|
-
|
|
3214
|
-
let history = createHashHistory({
|
|
3215
|
-
window
|
|
3216
|
-
});
|
|
3217
|
-
return createRouter(_extends({
|
|
3218
|
-
history
|
|
3219
|
-
}, routerInit));
|
|
3220
|
-
} ///////////////////////////////////////////////////////////////////////////////
|
|
3221
|
-
|
|
3222
3176
|
exports.AbortedDeferredError = AbortedDeferredError;
|
|
3223
3177
|
exports.ErrorResponse = ErrorResponse;
|
|
3224
3178
|
exports.IDLE_FETCHER = IDLE_FETCHER;
|
|
3225
3179
|
exports.IDLE_NAVIGATION = IDLE_NAVIGATION;
|
|
3226
3180
|
exports.UNSAFE_convertRoutesToDataRoutes = convertRoutesToDataRoutes;
|
|
3227
3181
|
exports.createBrowserHistory = createBrowserHistory;
|
|
3228
|
-
exports.createBrowserRouter = createBrowserRouter;
|
|
3229
3182
|
exports.createHashHistory = createHashHistory;
|
|
3230
|
-
exports.createHashRouter = createHashRouter;
|
|
3231
3183
|
exports.createMemoryHistory = createMemoryHistory;
|
|
3232
|
-
exports.createMemoryRouter = createMemoryRouter;
|
|
3233
3184
|
exports.createPath = createPath;
|
|
3234
3185
|
exports.createRouter = createRouter;
|
|
3235
3186
|
exports.defer = defer;
|