react-router
react-router copied to clipboard
Add support for `routes.ts`
TODO:
- [x] Opt-in Remix-style file conventions
- [x] Support using multiple routing strategies in parallel
- [x] vite-node to improve error messages when parsing routes code
- [ ] Remove built-in file system routing and
routesplugin option - [ ] Validate route files exist up front rather than letting Vite blow up when trying to import them?
- [ ] Handle ID generation for multiple routes pointing at the same file
- [ ] Validate ID uniqueness
- [ ] Back compat layer for Remix-style config routes?
⚠️ No Changeset found
Latest commit: 6f52a76808a3334e081a9083abd7cc6ced60ba2a
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Apologies for barging in, but can I ask what the benefit is of having to specify the /routes prefix for every route path? Can't we assume that 99.9% of apps will use this convention? Also, was wondering about having to import from @react-router/dev instead of react-router?
Anything that's only required at dev time comes from @react-router/dev — the CLI, Vite plugin(s), and now route config logic. This helps keep it out of node_modules for production deployments, but also makes it clear that these things are meant to work together as a set.
In terms of the /routes prefix, I'm (currently) deliberately keeping defineRoutes pretty unopinionated since:
- You might prefer to structure your project based on features rather than "routes" at the top level.
- You might also be running a file system routing strategy in parallel, so you may already be using the
routesdirectory for something else.
That said, there might be room to add a rootDirectory option like the @react-router/remix-v2-routes package provides.
@romansndlr Oh and by the way, you're not barging in at all, I appreciate the feedback 🙂
Couple notes from our discussion:
- Anything operating on the
routes.tsat the module-level should be pluralized to "routes" - Change package export to
/routesboth for consistency w/routes.ts, but also so we don't need "route" prefix/suffix for the imports - Change imports to
import { routes, route, index, layout, ... } from "@react-router/dev/routes" - Instead of
dev, maybe something that conveys "framework" and "compile-time" semantics. Something like@react-router/framework@react-router/build. Then we can also have a/viteexport on that.
🤖 Hello there,
We just published version 6.28.2-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!
Thanks!