Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faq typos #8357

Merged
merged 5 commits into from
Nov 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- mcansh
- kkirsche
- paulsmithkc
- noisypigeon
- elylucas
18 changes: 10 additions & 8 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ The majority of regexp routes were only concerned about one URL segment at a tim

A very common route we've seen is a regex matching multiple language codes:

```tsx filename=v5-regex-route.js
```tsx filename=v5-lang-route.js
function App() {
return (
<Switch>
Expand All @@ -292,7 +292,7 @@ function Lang({ params }) {

These are all actually just static paths, so in v6 you can make three routes and pass the code directly to the component. If you've got a lot of them, make an array and map it into routes to avoid the repetition.

```tsx filename=v6.js
```tsx filename=v6-lang-route.js
function App() {
return (
<Routes>
Expand All @@ -313,7 +313,7 @@ function Lang({ lang }) {

Another common case was ensuring that parameters were an integer.

```tsx filename=v5-regex-route.js
```tsx filename=v5-userId-route.js
function App() {
return (
<Switch>
Expand All @@ -330,11 +330,11 @@ function User({ params }) {

In this case you have to do a bit of work yourself with the regex inside the matching component:

```tsx filename=v5-regex-route.js
```tsx filename=v6-userId-route.js
function App() {
return (
<Routes>
<Route path="users/:id" element={<ValidateUser />} />
<Route path="/users/:id" element={<ValidateUser />} />
<Route path="/users/*" component={NotFound} />
</Routes>
);
Expand Down Expand Up @@ -397,17 +397,19 @@ In fact, the v5 version has all sorts of problems if your routes aren't ordered

If you're using [Remix](https://remix.run), you can send proper 40x responses to the browser by moving this work into your loader. This also decreases the size of the browser bundles sent to the user because loaders only run on the server.

```tsx
```tsx filename=remix-useLoaderData.js
import { useLoaderData } from "remix";

export async function loader({ params }) {
if (!params.id.match(/\d+/)) {
throw new Response("", { status: 400 });
}

let user = await fakeDb.user.find({ where: { id: params.id=}})
let user = await fakeDb.user.find({
where: { id: params.id }
});
if (!user) {
throw new Response("", { status: 404})
throw new Response("", { status: 404 });
}

return user;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4476,10 +4476,10 @@ history@^5.0.0:
dependencies:
"@babel/runtime" "^7.7.6"

history@^5.0.3:
version "5.0.3"
resolved "https://registry.npmjs.org/history/-/history-5.0.3.tgz#23d0b3046f695623c95a870506545e2b67e82edb"
integrity sha512-LoyCVOpCBkNAgrsdpTDZP77fys7lFDg8JdxTr7s6GHueZbTplKf8NAJu3y6/QuJIjk6TFsEGrhtILVP814X8+A==
history@^5.1.0:
version "5.1.0"
resolved "https://registry.npmjs.org/history/-/history-5.1.0.tgz#2e93c09c064194d38d52ed62afd0afc9d9b01ece"
integrity sha512-zPuQgPacm2vH2xdORvGGz1wQMuHSIB56yNAy5FnLuwOwgSYyPKptJtcMm6Ev+hRGeS+GzhbmRacHzvlESbFwDg==
dependencies:
"@babel/runtime" "^7.7.6"

Expand Down