Skip to content

Use react router in client components. #2348

Answered by Luzefiru
carloslato asked this question in Q&A
Discussion options

You must be logged in to vote

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!

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@carloslato
Comment options

@ntk221
Comment options

@Luzefiru
Comment options

Answer selected by carloslato
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants