Skip to content

Commit c7ec332

Browse files
committed
Fix readme example
1 parent 25da491 commit c7ec332

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Readme.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,14 @@ const toPath = compile("/user/:id", { encode: encodeURIComponent });
284284

285285
toPath({ id: 123 }); //=> "/user/123"
286286
toPath({ id: "café" }); //=> "/user/caf%C3%A9"
287-
toPath({ id: "/" }); //=> "/user/%2F"
288-
289287
toPath({ id: ":/" }); //=> "/user/%3A%2F"
290288

291289
// Without `encode`, you need to make sure inputs are encoded correctly.
292-
const toPathRaw = compile("/user/:id");
290+
// (Note: You can use `validate: false` to create an invalid paths.)
291+
const toPathRaw = compile("/user/:id", { validate: false });
293292

294293
toPathRaw({ id: "%3A%2F" }); //=> "/user/%3A%2F"
295-
toPathRaw({ id: ":/" }, { validate: false }); //=> "/user/:/"
294+
toPathRaw({ id: ":/" }); //=> "/user/:/"
296295

297296
const toPathRepeated = compile("/:segment+");
298297

@@ -303,8 +302,6 @@ const toPathRegexp = compile("/user/:id(\\d+)");
303302

304303
toPathRegexp({ id: 123 }); //=> "/user/123"
305304
toPathRegexp({ id: "123" }); //=> "/user/123"
306-
toPathRegexp({ id: "abc" }); //=> Throws `TypeError`.
307-
toPathRegexp({ id: "abc" }, { validate: false }); //=> "/user/abc"
308305
```
309306

310307
**Note:** The generated function will throw on invalid input.

0 commit comments

Comments
 (0)