FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
stevekrouse
stevekrousereactRouter7Example
Full-stack example ReactRouter7 project
Public
Like
3
reactRouter7Example
Home
Code
7
backend
2
frontend
3
routes
10
shared
2
README.md
TODO.md
react-router-questions.md
Branches
4
Pull requests
1
Remixes
2
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
react-router-questions.md
Code
/
react-router-questions.md
Search
4/10/2025
Viewing readonly version of main branch: v158
View latest version
react-router-questions.md

React Router Questions

I have some questions about how to set up React Router 7 as a "custom framework". It seems like the documentation on this is mostly these two pages:

  1. Docs on React Router 7: "Custom Framework"
  2. Example app on Github: @remix-run/custom-react-router-framework-example

How I've set it up

I'm using react-router 7.5.0, via esm.sh, and react 18.2.0.

Client loaders & actions

On the client, I turn loaders and actions into fetch calls to the backend. This is heavily inspired by here in the Github example.

Handling client loader & action API calls on the server

On the client, I check if the Accept header is JSON and then return the loader or action data. This is heavily inspired by here in the Github example.

Questions

1. Setting loader state for multiple loaders

Right now I've converted every loader into its own fetch call. This is the opposite of what frameworks refer to as "single fetch". However on the backend, I actually get access the full loaderData for all nested routes. I even wrote this silly function to combine all the loaderData objects into one big object.

Ideally we should make a single loader call per navigation event, and set the internal router state. In other words, I would like to somehow reach into React Router and set this state here:

Screenshot 2025-04-10 at 15.03.32@2x.png

And then let useLoaderData funnel the correct loader data's to the correct routes via their IDs.

2. Action redirects

When my backend returns a 302 from an action, how should I handle this on the frontend? For example, after you create a new topic on the home page, I redirect you to that topic's ID

However, I'm not sure how to handle this on the client here.

Ideally, I would do a proper React Router "navigation", and pass the relevant loader data along so it can be 100% client-side and require no other API calls.

3. Should I use queryRoute instead of query in my server?

The example app uses queryRoute instead of query for loaders and actions. I tried using that too but it didn't work. I think it returned undefined. I am now using query for everything.

Is it better to use that or is my use of query fine? I get the feeling that query is doing a bunch of work I don't need, ie SRR, but maybe that's not very expensive so it's fine? I noticed the example app uses X-Route-ID, so maybe I'd need to use that?

Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.