Skip to content

Commit c958936

Browse files
committed
Clarify match/compile examples in README
1 parent 140b824 commit c958936

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Readme.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ The `match` function returns a function for transforming paths into parameters:
202202
- **decode** Function for decoding strings for params, or `false` to disable entirely. (default: `decodeURIComponent`)
203203

204204
```js
205-
// Make sure you consistently `decode` segments.
206-
const fn = match("/user/:id", { decode: decodeURIComponent });
205+
const fn = match("/user/:id");
207206

208207
fn("/user/123"); //=> { path: '/user/123', index: 0, params: { id: '123' } }
209208
fn("/invalid"); //=> false
@@ -224,15 +223,14 @@ The `compile` function will return a function for transforming parameters into a
224223
```js
225224
const toPath = compile("/user/:id");
226225

227-
toPath({ id: 123 }); //=> "/user/123"
226+
toPath({ id: "name" }); //=> "/user/name"
228227
toPath({ id: "café" }); //=> "/user/caf%C3%A9"
229-
toPath({ id: ":/" }); //=> "/user/%3A%2F"
230228

231229
// When disabling `encode`, you need to make sure inputs are encoded correctly. No arrays are accepted.
232230
const toPathRaw = compile("/user/:id", { encode: false });
233231

234232
toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
235-
toPathRaw({ id: ":/" }); //=> "/user/:/", throws when `validate: false` is not set.
233+
toPathRaw({ id: ":/" }); //=> Throws, "/user/:/" when `validate` is `false`.
236234

237235
const toPathRepeated = compile("{/:segment}+");
238236

0 commit comments

Comments
 (0)