Skip to content

Commit a0ac387

Browse files
committed
docs: cleanup 404 examples that were added
1 parent b1c2e15 commit a0ac387

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

docs/how-to/file-route-conventions.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Usually your URLs aren't static but data-driven. Dynamic segments allow you to m
117117
The value will be parsed from the URL and passed to various APIs. We call these values "URL Parameters". The most useful places to access the URL params are in [loaders] and [actions].
118118

119119
```tsx
120-
export async function serverLoader({ params }) {
120+
export async function loader({ params }) {
121121
return fakeDb.getAllConcertsForCity(params.city);
122122
}
123123
```
@@ -127,7 +127,7 @@ You'll note the property name on the `params` object maps directly to the name o
127127
Routes can have multiple dynamic segments, like `concerts.$city.$date`, both are accessed on the params object by name:
128128

129129
```tsx
130-
export async function serverLoader({ params }) {
130+
export async function loader({ params }) {
131131
return fake.db.getConcerts({
132132
date: params.date,
133133
city: params.city,
@@ -285,7 +285,7 @@ While [dynamic segments][dynamic_segments] match a single path segment (the stuf
285285
Similar to dynamic route parameters, you can access the value of the matched path on the splat route's `params` with the `"*"` key.
286286

287287
```tsx filename=app/routes/files.$.tsx
288-
export async function serverLoader({ params }) {
288+
export async function loader({ params }) {
289289
const filePath = params["*"];
290290
return fake.getFileInfo(filePath);
291291
}
@@ -301,15 +301,12 @@ To create a route that will match any requests that don't match other defined ro
301301
| `/about` | `app/routes/about.tsx` |
302302
| `/any-invalid-path-will-match` | `app/routes/$.tsx` |
303303

304-
To have this route serve as a 404 page, be sure to modify the response code with a [`loader`](https://reactrouter.com/start/framework/data-loading#server-data-loading) function:
304+
By default the matched route will return a 200 response, so be sure to modify your catchall route to return a 404 instead:
305305

306-
```tsx
307-
import type { Route } from "./+types/$";
308-
export const loader = async ({
309-
request,
310-
}: Route.LoaderArgs) => {
306+
```tsx filename=app/routes/$.tsx
307+
export async function loader() {
311308
return data({}, 404);
312-
};
309+
}
313310
```
314311

315312
## Escaping Special Characters

docs/start/framework/routing.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,14 @@ const { "*": splat } = params;
303303

304304
You can also use a splat to catch requests that don't match any route:
305305

306-
```ts filename=app/routes.ts lines=[10]
307-
import {
308-
type RouteConfig,
309-
route,
310-
index,
311-
} from "@react-router/dev/routes";
306+
```ts filename=app/routes.ts
307+
route("*", "./catchall.tsx"); // catcall route,
308+
```
312309

313-
export default [
314-
index("./home.tsx"),
315-
route("about", "./about.tsx"),
316-
route("*", "./404.tsx"),
317-
] satisfies RouteConfig;
310+
```tsx filename=app/catchall.tsx
311+
export function loader() {
312+
throw new Response("Page not found", { status: 404 });
313+
}
318314
```
319315

320316
## Component Routes

0 commit comments

Comments
 (0)