Skip to content

Commit b246aa3

Browse files
authored
docs(how-to/file-route-conventions): clarify 404 response code in catch-all section (#13771)
1 parent 3cfb44e commit b246aa3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ 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:
305+
306+
```tsx
307+
import type { Route } from './+types/$';
308+
export const loader = async ({ request }: Route.LoaderArgs) => {
309+
return data({}, 404);
310+
};
311+
```
312+
304313
## Escaping Special Characters
305314

306315
If you want one of the special characters used for these route conventions to actually be a part of the URL, you can escape the conventions with `[]` characters. This can be especially helpful for [resource routes][resource_routes] that include an extension in the URL.

0 commit comments

Comments
 (0)