Skip to content

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Oct 1, 2025

export function AddToCart() {
  const productRoute = useRoute("routes/product")
  if (productRoute === undefined) throw new Error("Expected to be within product route")
  const { loaderData, actionData } = productRoute
  //          ^^^^^^^^^^^^^^^ these are now type-safe!
  return <div>{/* ... */}</div>
}

TODO

  • Register RouteModules type as a lookup from route ID to route module
  • Create new type-safe hook: useRoute<T>(routeId: T): UseRoute<T> | undefined
  • tests
    • Make sure to test eager declarations for route module exports (i.e. const not function)
  • changeset

Copy link

changeset-bot bot commented Oct 1, 2025

🦋 Changeset detected

Latest commit: a2bb8ab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
react-router Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
@react-router/architect Patch
@react-router/cloudflare Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
create-react-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

- no route ID -> { loaderData: unknown, actionData: unknown }
- actionData gets `| undefined` added to it
- `root` route is guaranteed to exist
since it could be accessed within an error boundary when the loader itself failed
@brookslybrand brookslybrand added the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Oct 2, 2025
Copy link
Contributor

github-actions bot commented Oct 2, 2025

Alpha release created: 0.0.0-experimental-c19b79d

⚠️ Note: This release was created from the HEAD of this branch so it may contain commits that have landed in dev but have not been released yet depending on when this branch was created. You can run the following command to see the commits that may not have been released yet:

git log --pretty=oneline [email protected]

@github-actions github-actions bot removed the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Oct 2, 2025
@pcattori pcattori changed the title useRoute unstable_useRoute Oct 2, 2025
@pcattori pcattori marked this pull request as ready for review October 3, 2025 18:18
@pcattori pcattori merged commit 45bad2b into dev Oct 3, 2025
8 checks passed
@pcattori pcattori deleted the pedro/use-route branch October 3, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants