Use react router in client components. #2348
-
Hi guys, I am testing the client components and I would like to know if it is possible to use react libraries like React Router. I tried but I got some errors in console:
My goal is to deploy an app in cloudflare pages and use /functions for the backend. My other alternative to solve my problem is to simply use React for the frontend, but I wanted to know if there was a way to do it entirely with hono. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I've got a sample repository with Hono on Cloudflare Pages found here. How it WorksThe index path After setting up the React script serving & router switching, you can add any routes or middleware just like you would any Hono app to the For ImprovementIf you have any feedback for it, feel free to raise an issue or make a PR as I'd like to improve on it for future reference. I hope this helps! |
Beta Was this translation helpful? Give feedback.
I've got a sample repository with Hono on Cloudflare Pages found here.
How it Works
The index path
/
renders the React client it simply calls a script to hydrate the React Router<RouteSwitch />
component. This successfully maps wildcard routes when you navigate to them via URL and you can simply start coding a SPA-like experience in the<RouteSwitch />
file.After setting up the React script serving & router switching, you can add any routes or middleware just like you would any Hono app to the
index.tsx
file.For Improvement
If you have any feedback for it, feel free to raise an issue or make a PR as I'd like to improve on it for future reference. I hope this helps!