react-router icon indicating copy to clipboard operation
react-router copied to clipboard

Add support for `routes.ts`

Open markdalgleish opened this issue 1 year ago • 1 comments

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 routes plugin 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?

markdalgleish avatar Jul 04 '24 13:07 markdalgleish

⚠️ 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

changeset-bot[bot] avatar Jul 04 '24 13:07 changeset-bot[bot]

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?

romansndlr avatar Jul 29 '24 12:07 romansndlr

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 routes directory for something else.

That said, there might be room to add a rootDirectory option like the @react-router/remix-v2-routes package provides.

markdalgleish avatar Jul 31 '24 01:07 markdalgleish

@romansndlr Oh and by the way, you're not barging in at all, I appreciate the feedback 🙂

markdalgleish avatar Aug 01 '24 00:08 markdalgleish

Couple notes from our discussion:

  • Anything operating on the routes.ts at the module-level should be pluralized to "routes"
  • Change package export to /routes both 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 /vite export on that.

pcattori avatar Aug 13 '24 01:08 pcattori

🤖 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!

github-actions[bot] avatar Jan 14 '25 16:01 github-actions[bot]