-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react-router-dom): add createModuleRoutes
utility function
#9830
Conversation
|
Hi @rossipedia, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run. Thanks! - The Remix team |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
Co-authored-by: Sergio Xalambrí <hello@sergiodxa.com>
Ahh that was the bit I was worried about. Does this kind of thing make sense for RR Native? If not, then I'd assume it should be moved to |
There’s no createNativeRouter to use loaders and actions in RR Native so this only work for the DOM package IMO |
Ok that's fine, I can move it directly into |
createModuleRoutes
utility function
Thanks for the proposal and POC @rossipedia! I'm going to close this now that it's being superseded by #10045. |
Discussion - Demo Project
The
createModuleRoutes()
utility is inspired by the Remix Route module convention. It allows a dev to provide amodule
function on their route that dynamically imports a route module with named exports, instead of explicitly adding those properties to the Route object.That is to say, it turns this:
into this:
Any properties set directly on the route object take precedence over module exports. So if you have specific routes you want to not lazy load the
loader
so it can fetch data as fast as possible, you just specifyloader
directly on the route alongside themodule
, and that will be the loader that gets invoked (the implementation won't even both trying to set up a lazy-loadedloader
in that case):The same goes for
action
,element
By leveraging
import()
andReact.lazy()
the implementation is super straightforward, and practically every build tool and bundler knows how to code-split when it sees that.I think this could be useful for a large number of React Router users by providing a "happy path" for code-splitting and lazy loading without being too heavy-handed.
It can also serve as a foundation for file-based routing plugins for things like Webpack/Vite/Parcel/etc.
This gives the developer a lever to pull between:
Which I think is very much in the Remix spirit of things :) Feedback welcome!
PS: I know I probably left out a bunch of stuff (docs/tests/etc), if this is something y'all are interested in merging I'll be sure to flesh out this PR with all those goodies. I also have next to zero experience with React Native, so not sure if this is something useful in that space either.