@remix-run/router 0.0.0-experimental-48058118
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 +170 -0
- package/LICENSE.md +22 -0
- package/README.md +107 -0
- package/dist/history.d.ts +249 -0
- package/dist/index.d.ts +7 -0
- package/dist/router.cjs.js +4204 -0
- package/dist/router.cjs.js.map +1 -0
- package/dist/router.d.ts +437 -0
- package/dist/router.js +4117 -0
- package/dist/router.js.map +1 -0
- package/dist/router.umd.js +4210 -0
- package/dist/router.umd.js.map +1 -0
- package/dist/router.umd.min.js +12 -0
- package/dist/router.umd.min.js.map +1 -0
- package/dist/utils.d.ts +481 -0
- package/history.ts +721 -0
- package/index.ts +93 -0
- package/package.json +33 -0
- package/router.ts +3851 -0
- package/utils.ts +1559 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# `@remix-run/router`
|
|
2
|
+
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixes 2 separate issues for revalidating fetcher `shouldRevalidate` calls ([#9948](https://github.com/remix-run/react-router/pull/9948))
|
|
8
|
+
- The `shouldRevalidate` function was only being called for _explicit_ revalidation scenarios (after a mutation, manual `useRevalidator` call, or an `X-Remix-Revalidate` header used for cookie setting in Remix). It was not properly being called on _implicit_ revalidation scenarios that also apply to navigation `loader` revalidation, such as a change in search params or clicking a link for the page we're already on. It's now correctly called in those additional scenarios.
|
|
9
|
+
- The parameters being passed were incorrect and inconsistent with one another since the `current*`/`next*` parameters reflected the static `fetcher.load` URL (and thus were identical). Instead, they should have reflected the the navigation that triggered the revalidation (as the `form*` parameters did). These parameters now correctly reflect the triggering navigation.
|
|
10
|
+
- Respect `preventScrollReset` on `<fetcher.Form>` ([#9963](https://github.com/remix-run/react-router/pull/9963))
|
|
11
|
+
- Do not short circuit on hash change only mutation submissions ([#9944](https://github.com/remix-run/react-router/pull/9944))
|
|
12
|
+
- Remove `instanceof` check from `isRouteErrorResponse` to avoid bundling issues on the server ([#9930](https://github.com/remix-run/react-router/pull/9930))
|
|
13
|
+
- Fix navigation for hash routers on manual URL changes ([#9980](https://github.com/remix-run/react-router/pull/9980))
|
|
14
|
+
- Detect when a `defer` call only contains critical data and remove the `AbortController` ([#9965](https://github.com/remix-run/react-router/pull/9965))
|
|
15
|
+
- Send the name as the value when url-encoding `File` `FormData` entries ([#9867](https://github.com/remix-run/react-router/pull/9867))
|
|
16
|
+
|
|
17
|
+
## 1.3.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- Added support for navigation blocking APIs ([#9709](https://github.com/remix-run/react-router/pull/9709))
|
|
22
|
+
- Expose deferred information from `createStaticHandler` ([#9760](https://github.com/remix-run/react-router/pull/9760))
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Improved absolute redirect url detection in actions/loaders ([#9829](https://github.com/remix-run/react-router/pull/9829))
|
|
27
|
+
- Fix URL creation with memory histories ([#9814](https://github.com/remix-run/react-router/pull/9814))
|
|
28
|
+
- Fix `generatePath` when optional params are present ([#9764](https://github.com/remix-run/react-router/pull/9764))
|
|
29
|
+
- Fix scroll reset if a submission redirects ([#9886](https://github.com/remix-run/react-router/pull/9886))
|
|
30
|
+
- Fix 404 bug with same-origin absolute redirects ([#9913](https://github.com/remix-run/react-router/pull/9913))
|
|
31
|
+
- Support `OPTIONS` requests in `staticHandler.queryRoute` ([#9914](https://github.com/remix-run/react-router/pull/9914))
|
|
32
|
+
|
|
33
|
+
## 1.2.1
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Include submission info in `shouldRevalidate` on action redirects ([#9777](https://github.com/remix-run/react-router/pull/9777), [#9782](https://github.com/remix-run/react-router/pull/9782))
|
|
38
|
+
- Reset `actionData` on action redirect to current location ([#9772](https://github.com/remix-run/react-router/pull/9772))
|
|
39
|
+
|
|
40
|
+
## 1.2.0
|
|
41
|
+
|
|
42
|
+
### Minor Changes
|
|
43
|
+
|
|
44
|
+
- Remove `unstable_` prefix from `createStaticHandler`/`createStaticRouter`/`StaticRouterProvider` ([#9738](https://github.com/remix-run/react-router/pull/9738))
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Fix explicit `replace` on submissions and `PUSH` on submission to new paths ([#9734](https://github.com/remix-run/react-router/pull/9734))
|
|
49
|
+
- Fix a few bugs where loader/action data wasn't properly cleared on errors ([#9735](https://github.com/remix-run/react-router/pull/9735))
|
|
50
|
+
- Prevent `useLoaderData` usage in `errorElement` ([#9735](https://github.com/remix-run/react-router/pull/9735))
|
|
51
|
+
- Skip initial scroll restoration for SSR apps with `hydrationData` ([#9664](https://github.com/remix-run/react-router/pull/9664))
|
|
52
|
+
|
|
53
|
+
## 1.1.0
|
|
54
|
+
|
|
55
|
+
This release introduces support for [Optional Route Segments](https://github.com/remix-run/react-router/issues/9546). Now, adding a `?` to the end of any path segment will make that entire segment optional. This works for both static segments and dynamic parameters.
|
|
56
|
+
|
|
57
|
+
**Optional Params Examples**
|
|
58
|
+
|
|
59
|
+
- Path `lang?/about` will match:
|
|
60
|
+
- `/:lang/about`
|
|
61
|
+
- `/about`
|
|
62
|
+
- Path `/multistep/:widget1?/widget2?/widget3?` will match:
|
|
63
|
+
- `/multistep`
|
|
64
|
+
- `/multistep/:widget1`
|
|
65
|
+
- `/multistep/:widget1/:widget2`
|
|
66
|
+
- `/multistep/:widget1/:widget2/:widget3`
|
|
67
|
+
|
|
68
|
+
**Optional Static Segment Example**
|
|
69
|
+
|
|
70
|
+
- Path `/home?` will match:
|
|
71
|
+
- `/`
|
|
72
|
+
- `/home`
|
|
73
|
+
- Path `/fr?/about` will match:
|
|
74
|
+
- `/about`
|
|
75
|
+
- `/fr/about`
|
|
76
|
+
|
|
77
|
+
### Minor Changes
|
|
78
|
+
|
|
79
|
+
- Allows optional routes and optional static segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Stop incorrectly matching on partial named parameters, i.e. `<Route path="prefix-:param">`, to align with how splat parameters work. If you were previously relying on this behavior then it's recommended to extract the static portion of the path at the `useParams` call site: ([#9506](https://github.com/remix-run/react-router/pull/9506))
|
|
84
|
+
|
|
85
|
+
```jsx
|
|
86
|
+
// Old behavior at URL /prefix-123
|
|
87
|
+
<Route path="prefix-:id" element={<Comp /> }>
|
|
88
|
+
|
|
89
|
+
function Comp() {
|
|
90
|
+
let params = useParams(); // { id: '123' }
|
|
91
|
+
let id = params.id; // "123"
|
|
92
|
+
...
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// New behavior at URL /prefix-123
|
|
96
|
+
<Route path=":id" element={<Comp /> }>
|
|
97
|
+
|
|
98
|
+
function Comp() {
|
|
99
|
+
let params = useParams(); // { id: 'prefix-123' }
|
|
100
|
+
let id = params.id.replace(/^prefix-/, ''); // "123"
|
|
101
|
+
...
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- Persist `headers` on `loader` `request`'s after SSR document `action` request ([#9721](https://github.com/remix-run/react-router/pull/9721))
|
|
106
|
+
- Fix requests sent to revalidating loaders so they reflect a GET request ([#9660](https://github.com/remix-run/react-router/pull/9660))
|
|
107
|
+
- Fix issue with deeply nested optional segments ([#9727](https://github.com/remix-run/react-router/pull/9727))
|
|
108
|
+
- GET forms now expose a submission on the loading navigation ([#9695](https://github.com/remix-run/react-router/pull/9695))
|
|
109
|
+
- Fix error boundary tracking for multiple errors bubbling to the same boundary ([#9702](https://github.com/remix-run/react-router/pull/9702))
|
|
110
|
+
|
|
111
|
+
## 1.0.5
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- Fix requests sent to revalidating loaders so they reflect a `GET` request ([#9680](https://github.com/remix-run/react-router/pull/9680))
|
|
116
|
+
- Remove `instanceof Response` checks in favor of `isResponse` ([#9690](https://github.com/remix-run/react-router/pull/9690))
|
|
117
|
+
- Fix `URL` creation in Cloudflare Pages or other non-browser-environments ([#9682](https://github.com/remix-run/react-router/pull/9682), [#9689](https://github.com/remix-run/react-router/pull/9689))
|
|
118
|
+
- Add `requestContext` support to static handler `query`/`queryRoute` ([#9696](https://github.com/remix-run/react-router/pull/9696))
|
|
119
|
+
- Note that the unstable API of `queryRoute(path, routeId)` has been changed to `queryRoute(path, { routeId, requestContext })`
|
|
120
|
+
|
|
121
|
+
## 1.0.4
|
|
122
|
+
|
|
123
|
+
### Patch Changes
|
|
124
|
+
|
|
125
|
+
- Throw an error if an `action`/`loader` function returns `undefined` as revalidations need to know whether the loader has previously been executed. `undefined` also causes issues during SSR stringification for hydration. You should always ensure you `loader`/`action` returns a value, and you may return `null` if you don't wish to return anything. ([#9511](https://github.com/remix-run/react-router/pull/9511))
|
|
126
|
+
- Properly handle redirects to external domains ([#9590](https://github.com/remix-run/react-router/pull/9590), [#9654](https://github.com/remix-run/react-router/pull/9654))
|
|
127
|
+
- Preserve the HTTP method on 307/308 redirects ([#9597](https://github.com/remix-run/react-router/pull/9597))
|
|
128
|
+
- Support `basename` in static data routers ([#9591](https://github.com/remix-run/react-router/pull/9591))
|
|
129
|
+
- Enhanced `ErrorResponse` bodies to contain more descriptive text in internal 403/404/405 scenarios
|
|
130
|
+
|
|
131
|
+
## 1.0.3
|
|
132
|
+
|
|
133
|
+
### Patch Changes
|
|
134
|
+
|
|
135
|
+
- Fix hrefs generated when using `createHashRouter` ([#9409](https://github.com/remix-run/react-router/pull/9409))
|
|
136
|
+
- fix encoding/matching issues with special chars ([#9477](https://github.com/remix-run/react-router/pull/9477), [#9496](https://github.com/remix-run/react-router/pull/9496))
|
|
137
|
+
- Support `basename` and relative routing in `loader`/`action` redirects ([#9447](https://github.com/remix-run/react-router/pull/9447))
|
|
138
|
+
- Ignore pathless layout routes when looking for proper submission `action` function ([#9455](https://github.com/remix-run/react-router/pull/9455))
|
|
139
|
+
- properly support `index` routes with a `path` in `useResolvedPath` ([#9486](https://github.com/remix-run/react-router/pull/9486))
|
|
140
|
+
- Add UMD build for `@remix-run/router` ([#9446](https://github.com/remix-run/react-router/pull/9446))
|
|
141
|
+
- fix `createURL` in local file execution in Firefox ([#9464](https://github.com/remix-run/react-router/pull/9464))
|
|
142
|
+
- Updates to `unstable_createStaticHandler` for incorporating into Remix ([#9482](https://github.com/remix-run/react-router/pull/9482), [#9465](https://github.com/remix-run/react-router/pull/9465))
|
|
143
|
+
|
|
144
|
+
## 1.0.2
|
|
145
|
+
|
|
146
|
+
### Patch Changes
|
|
147
|
+
|
|
148
|
+
- Reset `actionData` after a successful action redirect ([#9334](https://github.com/remix-run/react-router/pull/9334))
|
|
149
|
+
- Update `matchPath` to avoid false positives on dash-separated segments ([#9300](https://github.com/remix-run/react-router/pull/9300))
|
|
150
|
+
- If an index route has children, it will result in a runtime error. We have strengthened our `RouteObject`/`RouteProps` types to surface the error in TypeScript. ([#9366](https://github.com/remix-run/react-router/pull/9366))
|
|
151
|
+
|
|
152
|
+
## 1.0.1
|
|
153
|
+
|
|
154
|
+
### Patch Changes
|
|
155
|
+
|
|
156
|
+
- Preserve state from `initialEntries` ([#9288](https://github.com/remix-run/react-router/pull/9288))
|
|
157
|
+
- Preserve `?index` for fetcher get submissions to index routes ([#9312](https://github.com/remix-run/react-router/pull/9312))
|
|
158
|
+
|
|
159
|
+
## 1.0.0
|
|
160
|
+
|
|
161
|
+
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`.
|
|
162
|
+
|
|
163
|
+
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].
|
|
164
|
+
|
|
165
|
+
For an overview of the features provided by `@remix-run/router`, please check out the [`README`][remix-router-readme].
|
|
166
|
+
|
|
167
|
+
[rr-docs]: https://reactrouter.com
|
|
168
|
+
[rr-feature-overview]: https://reactrouter.com/start/overview
|
|
169
|
+
[rr-tutorial]: https://reactrouter.com/start/tutorial
|
|
170
|
+
[remix-router-readme]: https://github.com/remix-run/react-router/blob/main/packages/router/README.md
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) React Training 2015-2019
|
|
4
|
+
Copyright (c) Remix Software 2020-2022
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Remix Router
|
|
2
|
+
|
|
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
|
+
|
|
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].
|
|
10
|
+
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
A Router instance can be created using `createRouter`:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// Create and initialize a router. "initialize" contains all side effects
|
|
17
|
+
// including history listeners and kicking off the initial data fetch
|
|
18
|
+
let router = createRouter({
|
|
19
|
+
// Routes array
|
|
20
|
+
routes: ,
|
|
21
|
+
// History instance
|
|
22
|
+
history,
|
|
23
|
+
}).initialize()
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Internally, the Router represents the state in an object of the following format, which is available through `router.state`. You can also register a subscriber of the signature `(state: RouterState) => void` to execute when the state updates via `router.subscribe()`;
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
interface RouterState {
|
|
30
|
+
// False during the initial data load, true once we have our initial data
|
|
31
|
+
initialized: boolean;
|
|
32
|
+
// The `history` action of the most recently completed navigation
|
|
33
|
+
historyAction: Action;
|
|
34
|
+
// The current location of the router. During a navigation this reflects
|
|
35
|
+
// the "old" location and is updated upon completion of the navigation
|
|
36
|
+
location: Location;
|
|
37
|
+
// The current set of route matches
|
|
38
|
+
matches: DataRouteMatch[];
|
|
39
|
+
// The state of the current navigation
|
|
40
|
+
navigation: Navigation;
|
|
41
|
+
// The state of any in-progress router.revalidate() calls
|
|
42
|
+
revalidation: RevalidationState;
|
|
43
|
+
// Data from the loaders for the current matches
|
|
44
|
+
loaderData: RouteData;
|
|
45
|
+
// Data from the action for the current matches
|
|
46
|
+
actionData: RouteData | null;
|
|
47
|
+
// Errors thrown from loaders/actions for the current matches
|
|
48
|
+
errors: RouteData | null;
|
|
49
|
+
// Map of all active fetchers
|
|
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;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Navigations
|
|
61
|
+
|
|
62
|
+
All navigations are done through the `router.navigate` API which is overloaded to support different types of navigations:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
// Link navigation (pushes onto the history stack by default)
|
|
66
|
+
router.navigate("/page");
|
|
67
|
+
|
|
68
|
+
// Link navigation (replacing the history stack)
|
|
69
|
+
router.navigate("/page", { replace: true });
|
|
70
|
+
|
|
71
|
+
// Pop navigation (moving backward/forward in the history stack)
|
|
72
|
+
router.navigate(-1);
|
|
73
|
+
|
|
74
|
+
// Form submission navigation
|
|
75
|
+
let formData = new FormData();
|
|
76
|
+
formData.append(key, value);
|
|
77
|
+
router.navigate("/page", {
|
|
78
|
+
formMethod: "post",
|
|
79
|
+
formData,
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Fetchers
|
|
84
|
+
|
|
85
|
+
Fetchers are a mechanism to call loaders/actions without triggering a navigation, and are done through the `router.fetch()` API. All fetch calls require a unique key to identify the fetcher.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
// Execute the loader for /page
|
|
89
|
+
router.fetch("key", "/page");
|
|
90
|
+
|
|
91
|
+
// Submit to the action for /page
|
|
92
|
+
let formData = new FormData();
|
|
93
|
+
formData.append(key, value);
|
|
94
|
+
router.fetch("key", "/page", {
|
|
95
|
+
formMethod: "post",
|
|
96
|
+
formData,
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Revalidation
|
|
101
|
+
|
|
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
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actions represent the type of change to a location value.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum Action {
|
|
5
|
+
/**
|
|
6
|
+
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
7
|
+
* as a back or forward navigation. It does not describe the direction of the
|
|
8
|
+
* navigation, only that the current index changed.
|
|
9
|
+
*
|
|
10
|
+
* Note: This is the default action for newly created history objects.
|
|
11
|
+
*/
|
|
12
|
+
Pop = "POP",
|
|
13
|
+
/**
|
|
14
|
+
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
15
|
+
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
16
|
+
* entries in the stack are lost.
|
|
17
|
+
*/
|
|
18
|
+
Push = "PUSH",
|
|
19
|
+
/**
|
|
20
|
+
* A REPLACE indicates the entry at the current index in the history stack
|
|
21
|
+
* being replaced by a new one.
|
|
22
|
+
*/
|
|
23
|
+
Replace = "REPLACE"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The pathname, search, and hash values of a URL.
|
|
27
|
+
*/
|
|
28
|
+
export interface Path {
|
|
29
|
+
/**
|
|
30
|
+
* A URL pathname, beginning with a /.
|
|
31
|
+
*/
|
|
32
|
+
pathname: string;
|
|
33
|
+
/**
|
|
34
|
+
* A URL search string, beginning with a ?.
|
|
35
|
+
*/
|
|
36
|
+
search: string;
|
|
37
|
+
/**
|
|
38
|
+
* A URL fragment identifier, beginning with a #.
|
|
39
|
+
*/
|
|
40
|
+
hash: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An entry in a history stack. A location contains information about the
|
|
44
|
+
* URL path, as well as possibly some arbitrary state and a key.
|
|
45
|
+
*/
|
|
46
|
+
export interface Location extends Path {
|
|
47
|
+
/**
|
|
48
|
+
* A value of arbitrary data associated with this location.
|
|
49
|
+
*/
|
|
50
|
+
state: any;
|
|
51
|
+
/**
|
|
52
|
+
* A unique string associated with this location. May be used to safely store
|
|
53
|
+
* and retrieve data in some other storage API, like `localStorage`.
|
|
54
|
+
*
|
|
55
|
+
* Note: This value is always "default" on the initial location.
|
|
56
|
+
*/
|
|
57
|
+
key: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A change to the current location.
|
|
61
|
+
*/
|
|
62
|
+
export interface Update {
|
|
63
|
+
/**
|
|
64
|
+
* The action that triggered the change.
|
|
65
|
+
*/
|
|
66
|
+
action: Action;
|
|
67
|
+
/**
|
|
68
|
+
* The new location.
|
|
69
|
+
*/
|
|
70
|
+
location: Location;
|
|
71
|
+
/**
|
|
72
|
+
* The delta between this location and the former location in the history stack
|
|
73
|
+
*/
|
|
74
|
+
delta: number | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A function that receives notifications about location changes.
|
|
78
|
+
*/
|
|
79
|
+
export interface Listener {
|
|
80
|
+
(update: Update): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Describes a location that is the destination of some navigation, either via
|
|
84
|
+
* `history.push` or `history.replace`. May be either a URL or the pieces of a
|
|
85
|
+
* URL path.
|
|
86
|
+
*/
|
|
87
|
+
export declare type To = string | Partial<Path>;
|
|
88
|
+
/**
|
|
89
|
+
* A history is an interface to the navigation stack. The history serves as the
|
|
90
|
+
* source of truth for the current location, as well as provides a set of
|
|
91
|
+
* methods that may be used to change it.
|
|
92
|
+
*
|
|
93
|
+
* It is similar to the DOM's `window.history` object, but with a smaller, more
|
|
94
|
+
* focused API.
|
|
95
|
+
*/
|
|
96
|
+
export interface History {
|
|
97
|
+
/**
|
|
98
|
+
* The last action that modified the current location. This will always be
|
|
99
|
+
* Action.Pop when a history instance is first created. This value is mutable.
|
|
100
|
+
*/
|
|
101
|
+
readonly action: Action;
|
|
102
|
+
/**
|
|
103
|
+
* The current location. This value is mutable.
|
|
104
|
+
*/
|
|
105
|
+
readonly location: Location;
|
|
106
|
+
/**
|
|
107
|
+
* Returns a valid href for the given `to` value that may be used as
|
|
108
|
+
* the value of an <a href> attribute.
|
|
109
|
+
*
|
|
110
|
+
* @param to - The destination URL
|
|
111
|
+
*/
|
|
112
|
+
createHref(to: To): string;
|
|
113
|
+
/**
|
|
114
|
+
* Returns a URL for the given `to` value
|
|
115
|
+
*
|
|
116
|
+
* @param to - The destination URL
|
|
117
|
+
*/
|
|
118
|
+
createURL(to: To): URL;
|
|
119
|
+
/**
|
|
120
|
+
* Encode a location the same way window.history would do (no-op for memory
|
|
121
|
+
* history) so we ensure our PUSH/REPLACE navigations for data routers
|
|
122
|
+
* behave the same as POP
|
|
123
|
+
*
|
|
124
|
+
* @param to Unencoded path
|
|
125
|
+
*/
|
|
126
|
+
encodeLocation(to: To): Path;
|
|
127
|
+
/**
|
|
128
|
+
* Pushes a new location onto the history stack, increasing its length by one.
|
|
129
|
+
* If there were any entries in the stack after the current one, they are
|
|
130
|
+
* lost.
|
|
131
|
+
*
|
|
132
|
+
* @param to - The new URL
|
|
133
|
+
* @param state - Data to associate with the new location
|
|
134
|
+
*/
|
|
135
|
+
push(to: To, state?: any): void;
|
|
136
|
+
/**
|
|
137
|
+
* Replaces the current location in the history stack with a new one. The
|
|
138
|
+
* location that was replaced will no longer be available.
|
|
139
|
+
*
|
|
140
|
+
* @param to - The new URL
|
|
141
|
+
* @param state - Data to associate with the new location
|
|
142
|
+
*/
|
|
143
|
+
replace(to: To, state?: any): void;
|
|
144
|
+
/**
|
|
145
|
+
* Navigates `n` entries backward/forward in the history stack relative to the
|
|
146
|
+
* current index. For example, a "back" navigation would use go(-1).
|
|
147
|
+
*
|
|
148
|
+
* @param delta - The delta in the stack index
|
|
149
|
+
*/
|
|
150
|
+
go(delta: number): void;
|
|
151
|
+
/**
|
|
152
|
+
* Sets up a listener that will be called whenever the current location
|
|
153
|
+
* changes.
|
|
154
|
+
*
|
|
155
|
+
* @param listener - A function that will be called when the location changes
|
|
156
|
+
* @returns unlisten - A function that may be used to stop listening
|
|
157
|
+
*/
|
|
158
|
+
listen(listener: Listener): () => void;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A user-supplied object that describes a location. Used when providing
|
|
162
|
+
* entries to `createMemoryHistory` via its `initialEntries` option.
|
|
163
|
+
*/
|
|
164
|
+
export declare type InitialEntry = string | Partial<Location>;
|
|
165
|
+
export declare type MemoryHistoryOptions = {
|
|
166
|
+
initialEntries?: InitialEntry[];
|
|
167
|
+
initialIndex?: number;
|
|
168
|
+
v5Compat?: boolean;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* A memory history stores locations in memory. This is useful in stateful
|
|
172
|
+
* environments where there is no web browser, such as node tests or React
|
|
173
|
+
* Native.
|
|
174
|
+
*/
|
|
175
|
+
export interface MemoryHistory extends History {
|
|
176
|
+
/**
|
|
177
|
+
* The current index in the history stack.
|
|
178
|
+
*/
|
|
179
|
+
readonly index: number;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Memory history stores the current location in memory. It is designed for use
|
|
183
|
+
* in stateful non-browser environments like tests and React Native.
|
|
184
|
+
*/
|
|
185
|
+
export declare function createMemoryHistory(options?: MemoryHistoryOptions): MemoryHistory;
|
|
186
|
+
/**
|
|
187
|
+
* A browser history stores the current location in regular URLs in a web
|
|
188
|
+
* browser environment. This is the standard for most web apps and provides the
|
|
189
|
+
* cleanest URLs the browser's address bar.
|
|
190
|
+
*
|
|
191
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
|
|
192
|
+
*/
|
|
193
|
+
export interface BrowserHistory extends UrlHistory {
|
|
194
|
+
}
|
|
195
|
+
export declare type BrowserHistoryOptions = UrlHistoryOptions;
|
|
196
|
+
/**
|
|
197
|
+
* Browser history stores the location in regular URLs. This is the standard for
|
|
198
|
+
* most web apps, but it requires some configuration on the server to ensure you
|
|
199
|
+
* serve the same app at multiple URLs.
|
|
200
|
+
*
|
|
201
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
202
|
+
*/
|
|
203
|
+
export declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
|
|
204
|
+
/**
|
|
205
|
+
* A hash history stores the current location in the fragment identifier portion
|
|
206
|
+
* of the URL in a web browser environment.
|
|
207
|
+
*
|
|
208
|
+
* This is ideal for apps that do not control the server for some reason
|
|
209
|
+
* (because the fragment identifier is never sent to the server), including some
|
|
210
|
+
* shared hosting environments that do not provide fine-grained controls over
|
|
211
|
+
* which pages are served at which URLs.
|
|
212
|
+
*
|
|
213
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
|
|
214
|
+
*/
|
|
215
|
+
export interface HashHistory extends UrlHistory {
|
|
216
|
+
}
|
|
217
|
+
export declare type HashHistoryOptions = UrlHistoryOptions;
|
|
218
|
+
/**
|
|
219
|
+
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
220
|
+
* for situations where you don't want to send the location to the server for
|
|
221
|
+
* some reason, either because you do cannot configure it or the URL space is
|
|
222
|
+
* reserved for something else.
|
|
223
|
+
*
|
|
224
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
225
|
+
*/
|
|
226
|
+
export declare function createHashHistory(options?: HashHistoryOptions): HashHistory;
|
|
227
|
+
/**
|
|
228
|
+
* @private
|
|
229
|
+
*/
|
|
230
|
+
export declare function invariant(value: boolean, message?: string): asserts value;
|
|
231
|
+
export declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
|
|
232
|
+
/**
|
|
233
|
+
* Creates a Location object with a unique key from the given Path
|
|
234
|
+
*/
|
|
235
|
+
export declare function createLocation(current: string | Location, to: To, state?: any, key?: string): Readonly<Location>;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a string URL path from the given pathname, search, and hash components.
|
|
238
|
+
*/
|
|
239
|
+
export declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
|
|
240
|
+
/**
|
|
241
|
+
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
242
|
+
*/
|
|
243
|
+
export declare function parsePath(path: string): Partial<Path>;
|
|
244
|
+
export interface UrlHistory extends History {
|
|
245
|
+
}
|
|
246
|
+
export declare type UrlHistoryOptions = {
|
|
247
|
+
window?: Window;
|
|
248
|
+
v5Compat?: boolean;
|
|
249
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { ActionFunction, ActionFunctionArgs, ActionFunctionWithMiddleware, ActionFunctionArgsWithMiddleware, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, TrackedPromise, FormEncType, FormMethod, JsonFunction, LoaderFunction, LoaderFunctionArgs, LoaderFunctionWithMiddleware, LoaderFunctionArgsWithMiddleware, MiddlewareContext, MiddlewareFunction, MiddlewareFunctionArgs, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, ShouldRevalidateFunction, Submission, } from "./utils";
|
|
2
|
+
export { AbortedDeferredError, ErrorResponse, createMiddlewareContext, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils";
|
|
3
|
+
export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
|
|
4
|
+
export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, invariant, parsePath, } from "./history";
|
|
5
|
+
export * from "./router";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export { DeferredData as UNSAFE_DeferredData, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, getPathContributingMatches as UNSAFE_getPathContributingMatches, createMiddlewareStore as UNSAFE_createMiddlewareStore, } from "./utils";
|