Skip to content

Commit eae1f6b

Browse files
sgmondakodiakhq[bot]
authored andcommitted
Dynamic routes clarification (#8110)
As talked in #8101 dynamic routing documentation could be confusing. This PR tries to clarify it a bit.
1 parent 8b0a93b commit eae1f6b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/next/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,20 @@ A `<Link>` for `/post/abc` looks like so:
311311
</Link>
312312
```
313313

314-
- `href`: the path inside `pages` directory
315-
- `as`: the path that will be rendered in the browser URL bar
314+
- `href`: the path inside `pages` directory.
315+
- `as`: the path that will be rendered in the browser URL bar.
316+
317+
As `href` is a filesystem path, it shouldn't change at runtime, instead, you will probably need to change `as`
318+
dynamically according to your needs. Here's an example to create a list of links:
319+
320+
```jsx
321+
const pids = ['id1', 'id2', 'id3'];
322+
{pids.map(pid => (
323+
<Link href="/post/[pid]" as={`/post/${pid}`}>
324+
<a>Post {pid}</a>
325+
</Link>
326+
))}
327+
```
316328

317329
> You can [read more about `<Link>` here](#with-link).
318330

0 commit comments

Comments
 (0)