Releases: rphlmr/react-router-hono-server
v2.9.0
v2.8.5
v2.8.4
What's Changed
- fix: resolve build cloudflare in react 19 by @ikhbaaalll in #74
New Contributors
- @ikhbaaalll made their first contribution in #74
Full Changelog: v2.8.2...v2.8.3
v2.8.2
v2.8.1
v2.8.0
What's Changed
Full Changelog: v2.7.1...v2.8.0
v2.7.1
What's Changed
Check: https://github.com/rphlmr/react-router-hono-server?tab=readme-ov-file#middleware
import { redirect } from "react-router-hono-server/http";
Full Changelog: v2.6.4...v2.7.0
v2.6.4
What's Changed
Full Changelog: v2.5.0...v2.6.0
- Add Vite 6 as a peer dependency (keeping Vite 5 too).
- Fix build loader for cloudflare
- Fix missing
AppLoadContext
in dev (dev server issue) - Add support for React Router
basename
- Handle React Router app as a Hono sub app
- [Cloudflare]: setting
experimental_serve_directly
in wrangler config will now use your Hono server to serve assets - Remove deprecated
honoOptions
in favor ofapp
option (createHonoServer
) - Temporary handle React Router issue (remix-run/react-router#12295)
Basename and Hono sub apps
Note
By default, the React Router app is mounted at /
(default basename
value).
You may not need to use this option. It's for advanced use cases.
Tip
Check this example to see how to use it.
You can use the basename
option in your React Router config (react-router.config.ts
) to mount your React Router app on a subpath.
It will automatically mount the app on the subpath.
// react-router.config.ts
import type { Config } from "@react-router/dev/config";
export default {
basename: "/app", // Now the React Router app will be mounted on /app
} satisfies Config;
Then, you can use the app
option in createHonoServer
to pass your "root" Hono app. This will be used to mount the React Router app on the basename
path.
import { Hono } from "hono";
import { createHonoServer } from "react-router-hono-server/node";
import { API_BASENAME, api } from "./api";
import { getLoadContext } from "./context";
// Create a root Hono app
const app = new Hono();
// Mount the API app at /api
app.route(API_BASENAME, api);
export default await createHonoServer({
// Pass the root Hono app to the server.
// It will be used to mount the React Router app on the `basename` defined in react-router.config.ts
app,
getLoadContext,
});
Note
You now have two entry points!
/api
- for your API/app
- for your React Router app
Cloudflare custom assets serving
You can set Cloudflare experimental_serve_directly
and delegate assets serving to Hono, like for Node and Bun.
Tip
Check https://developers.cloudflare.com/workers/static-assets/binding/#experimental_serve_directly
Tip
Check this example to see how to use it.
[assets]
directory = "./build/client/"
binding = "ASSETS"
experimental_serve_directly = false
v2.5.0
New
new helper: reactRouterRedirect
Redirect to a new location in a way that React Router can handle (Single fetch protocol).
🚨 Redirecting from a middleware
Important
You have to use the reactRouterRedirect
helper to redirect from a middleware.
It returns a single-fetch-like response.
If you use c.redirect
, it will not work as expected and you will get a Unable to decode turbo-stream response
error.
import { reactRouterRedirect } from "react-router-hono-server/http";
new createHonoServer option: beforeAll
You can use the beforeAll
option to add middleware that runs before any built-in middleware, including assets serving.
You can use it to add protection middleware, for example.
Tip
When you check the path to protect, don't forget to use c.req.path.includes("")
to handle .data
requests (loader
)!
import { reactRouterRedirect } from "react-router-hono-server/http";
import { createHonoServer } from "react-router-hono-server/node";
export default await createHonoServer({
beforeAll(app) {
app.use(async (c, next) => {
if (c.req.path.includes("/protected") && !c.req.header("Authorization")) {
return reactRouterRedirect("/login");
}
return next();
});
},
});
new createHonoServer option: overrideGlobalObjects
https://github.com/honojs/node-server?tab=readme-ov-file#overrideglobalobjects
It is now set to false
by default to prevent some issues with 3rd party libs like remix-hook-form
.
Enabling this makes request.clone()
not an instanceof Request
.
export default await createHonoServer({
overrideGlobalObjects: true,
});
Fixes
What's Changed
- added cloudflare d1-drizzle example by @diurivj in #45
- Handle Single fetch redirects by @rphlmr in #43
New Contributors
Full Changelog: v2.4.0...v2.5.0