Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
"@playground/split-route-modules-spa": "0.0.0",
"@playground/vite-plugin-cloudflare": "0.0.0"
},
"changesets": []
"changesets": [
"breezy-planes-roll",
"green-pens-push",
"quick-eels-join",
"six-lobsters-think"
]
}
2 changes: 2 additions & 0 deletions packages/create-react-router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `create-react-router`

## 7.9.4-pre.0

## 7.9.3

## 7.9.2
Expand Down
2 changes: 1 addition & 1 deletion packages/create-react-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-react-router",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Create a new React Router app",
"homepage": "https://reactrouter.com",
"bugs": {
Expand Down
8 changes: 8 additions & 0 deletions packages/react-router-architect/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# `@react-router/architect`

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `[email protected]`
- `@react-router/[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-architect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/architect",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Architect server request handler for React Router",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
7 changes: 7 additions & 0 deletions packages/react-router-cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# `@react-router/cloudflare`

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/cloudflare",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Cloudflare platform abstractions for React Router",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
110 changes: 110 additions & 0 deletions packages/react-router-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,115 @@
# `@react-router/dev`

## 7.9.4-pre.0

### Patch Changes

- Update `valibot` dependency to `^1.1.0` ([#14379](https://github.com/remix-run/react-router/pull/14379))
- New (unstable) `useRoute` hook for accessing data from specific routes ([#14407](https://github.com/remix-run/react-router/pull/14407))

For example, let's say you have an `admin` route somewhere in your app and you want any child routes of `admin` to all have access to the `loaderData` and `actionData` from `admin.`

```tsx
// app/routes/admin.tsx
import { Outlet } from "react-router";

export const loader = () => ({ message: "Hello, loader!" });

export const action = () => ({ count: 1 });

export default function Component() {
return (
<div>
{/* ... */}
<Outlet />
{/* ... */}
</div>
);
}
```

You might even want to create a reusable widget that all of the routes nested under `admin` could use:

```tsx
import { unstable_useRoute as useRoute } from "react-router";

export function AdminWidget() {
// How to get `message` and `count` from `admin` route?
}
```

In framework mode, `useRoute` knows all your app's routes and gives you TS errors when invalid route IDs are passed in:

```tsx
export function AdminWidget() {
const admin = useRoute("routes/dmin");
// ^^^^^^^^^^^
}
```

`useRoute` returns `undefined` if the route is not part of the current page:

```tsx
export function AdminWidget() {
const admin = useRoute("routes/admin");
if (!admin) {
throw new Error(`AdminWidget used outside of "routes/admin"`);
}
}
```

Note: the `root` route is the exception since it is guaranteed to be part of the current page.
As a result, `useRoute` never returns `undefined` for `root`.

`loaderData` and `actionData` are marked as optional since they could be accessed before the `action` is triggered or after the `loader` threw an error:

```tsx
export function AdminWidget() {
const admin = useRoute("routes/admin");
if (!admin) {
throw new Error(`AdminWidget used outside of "routes/admin"`);
}
const { loaderData, actionData } = admin;
console.log(loaderData);
// ^? { message: string } | undefined
console.log(actionData);
// ^? { count: number } | undefined
}
```

If instead of a specific route, you wanted access to the _current_ route's `loaderData` and `actionData`, you can call `useRoute` without arguments:

```tsx
export function AdminWidget() {
const currentRoute = useRoute();
currentRoute.loaderData;
currentRoute.actionData;
}
```

This usage is equivalent to calling `useLoaderData` and `useActionData`, but consolidates all route data access into one hook: `useRoute`.

Note: when calling `useRoute()` (without a route ID), TS has no way to know which route is the current route.
As a result, `loaderData` and `actionData` are typed as `unknown`.
If you want more type-safety, you can either narrow the type yourself with something like `zod` or you can refactor your app to pass down typed props to your `AdminWidget`:

```tsx
export function AdminWidget({
message,
count,
}: {
message: string;
count: number;
}) {
/* ... */
}
```

- Updated dependencies:
- `[email protected]`
- `@react-router/[email protected]`
- `@react-router/[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/dev",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Dev tools and CLI for React Router",
"homepage": "https://reactrouter.com",
"bugs": {
Expand Down
7 changes: 7 additions & 0 deletions packages/react-router-dom/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# react-router-dom

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router-dom",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Declarative routing for React web applications",
"keywords": [
"react",
Expand Down
8 changes: 8 additions & 0 deletions packages/react-router-express/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# `@react-router/express`

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `[email protected]`
- `@react-router/[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-express/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/express",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Express server request handler for React Router",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
7 changes: 7 additions & 0 deletions packages/react-router-fs-routes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# `@react-router/fs-routes`

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `@react-router/[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-fs-routes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/fs-routes",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "File system routing conventions for React Router, for use within routes.ts",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
8 changes: 8 additions & 0 deletions packages/react-router-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# `@react-router/node`

## 7.9.4-pre.0

### Patch Changes

- Validate format of incoming session ids ([#14426](https://github.com/remix-run/react-router/pull/14426))
- Updated dependencies:
- `[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/node",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Node.js platform abstractions for React Router",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# `@react-router/remix-config-routes-adapter`

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `@react-router/[email protected]`

## 7.9.3

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/remix-routes-option-adapter",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Adapter for Remix's \"routes\" config option, for use within routes.ts",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
9 changes: 9 additions & 0 deletions packages/react-router-serve/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# `@react-router/serve`

## 7.9.4-pre.0

### Patch Changes

- Updated dependencies:
- `[email protected]`
- `@react-router/[email protected]`
- `@react-router/[email protected]`

## 7.9.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-serve/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-router/serve",
"version": "7.9.3",
"version": "7.9.4-pre.0",
"description": "Production application server for React Router",
"bugs": {
"url": "https://github.com/remix-run/react-router/issues"
Expand Down
Loading