react-router-hono-server 2.6.3 → 2.7.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/README.md +10 -2
- package/dist/http.d.ts +11 -1
- package/dist/http.js +8 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -508,15 +508,23 @@ export interface HonoServerOptions<E extends Env = BlankEnv> extends Omit<HonoSe
|
|
|
508
508
|
|
|
509
509
|
🚨 Redirecting from a middleware
|
|
510
510
|
> [!IMPORTANT]
|
|
511
|
-
>
|
|
511
|
+
> TLDR: If you encounter a `Error: Unable to decode turbo-stream response` after a redirect from your middleware, try to use `redirect` instead of `c.redirect`.
|
|
512
|
+
>
|
|
513
|
+
> `redirect` will use `c.redirect` for "normal" requests and a single-fetch-like response for React Router `.data` requests.
|
|
514
|
+
>
|
|
515
|
+
> If the next handler is a Hono middleware (ex: https://github.com/rphlmr/react-router-hono-server/discussions/56), you can use `c.redirect` as usual.
|
|
516
|
+
>
|
|
517
|
+
> You **have to** use the `redirect` helper to redirect from a middleware if the next handler that will receive this redirect is a React Router route.
|
|
512
518
|
>
|
|
513
519
|
> It returns a single-fetch-like response.
|
|
514
520
|
>
|
|
515
521
|
> If you use `c.redirect`, it will not work as expected and you will get a `Unable to decode turbo-stream response` error.
|
|
516
522
|
>
|
|
517
523
|
>```ts
|
|
518
|
-
> import {
|
|
524
|
+
> import { redirect } from "react-router-hono-server/http";
|
|
519
525
|
>```
|
|
526
|
+
>
|
|
527
|
+
> I'm sorry for this inconvenience, I hope it can be "fixed" in future React Router versions.
|
|
520
528
|
|
|
521
529
|
Middleware are functions that are called before React Router calls your loader/action.
|
|
522
530
|
|
package/dist/http.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Redirect to a new location in a way that React Router can handle.
|
|
3
5
|
*
|
|
4
6
|
* It follows the Single Fetch Redirect protocol.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use `redirect` instead. `import { reactRouterRedirect } from "react-router-hono-server/http"`
|
|
5
9
|
*/
|
|
6
10
|
declare function reactRouterRedirect(location: string): Response;
|
|
11
|
+
/**
|
|
12
|
+
* Redirect to a new location.
|
|
13
|
+
*
|
|
14
|
+
* It follows the Single Fetch Redirect protocol, if the request path ends with `.data`.
|
|
15
|
+
*/
|
|
16
|
+
declare function redirect(c: Context, location: string): Response;
|
|
7
17
|
|
|
8
|
-
export { reactRouterRedirect };
|
|
18
|
+
export { reactRouterRedirect, redirect };
|
package/dist/http.js
CHANGED
|
@@ -38,6 +38,13 @@ function reactRouterRedirect(location) {
|
|
|
38
38
|
}
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
|
+
function redirect(c, location) {
|
|
42
|
+
if (c.req.path.includes(".data")) {
|
|
43
|
+
return reactRouterRedirect(location);
|
|
44
|
+
}
|
|
45
|
+
return c.redirect(location);
|
|
46
|
+
}
|
|
41
47
|
export {
|
|
42
|
-
reactRouterRedirect
|
|
48
|
+
reactRouterRedirect,
|
|
49
|
+
redirect
|
|
43
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
|
|
6
6
|
"exports": {
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"default": "./dist/dev.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
-
"./
|
|
35
|
+
"./middleware": {
|
|
36
36
|
"import": {
|
|
37
|
-
"import": "./dist/
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"default": "./dist/
|
|
37
|
+
"import": "./dist/middleware.js",
|
|
38
|
+
"types": "./dist/middleware.d.ts",
|
|
39
|
+
"default": "./dist/middleware.js"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"./http": {
|