Skip to content

Commit

Permalink
docs(router): clarify dynamic route slug is about a file name, not "f…
Browse files Browse the repository at this point in the history
…older" (#56596)

### What?

Update documentation on dynamic routing to clarify the use of segment names within file names, rather than referring to them as "folder names".

### Why?

The original documentation used the example term `folderName` when it was referencing dynamic segment names within filenames.  The paths being described here are file names but not folders, and end in a file extension.  This could confuse readers and developers, especially those new to Next.js, leading to potential misunderstandings and misconfigurations.  Perhaps folderName was a relic of a different example wrapping a folder name to do a nested path or other configuration?  But here it seems out of place.

### How?

- Reviewed the provided documentation sections on dynamic routing.
- Replaced references to "folderName" with a different term "segmentName". 
- Ensured the examples provided in the documentation correctly showcase the use of segment names within filenames.
  • Loading branch information
cmbritten committed Oct 10, 2023
1 parent 260ea16 commit c8064d6
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -13,7 +13,7 @@ When you don't know the exact segment names ahead of time and want to create rou

## Convention

A Dynamic Segment can be created by wrapping a folder's name in square brackets: `[folderName]`. For example, `[id]` or `[slug]`.
A Dynamic Segment can be created by wrapping a file or folder name in square brackets: `[segmentName]`. For example, `[id]` or `[slug]`.

Dynamic Segments can be accessed from [`useRouter`](/docs/pages/api-reference/functions/use-router).

Expand All @@ -38,7 +38,7 @@ export default function Page() {

## Catch-all Segments

Dynamic Segments can be extended to **catch-all** subsequent segments by adding an ellipsis inside the brackets `[...folderName]`.
Dynamic Segments can be extended to **catch-all** subsequent segments by adding an ellipsis inside the brackets `[...segmentName]`.

For example, `pages/shop/[...slug].js` will match `/shop/clothes`, but also `/shop/clothes/tops`, `/shop/clothes/tops/t-shirts`, and so on.

Expand All @@ -50,7 +50,7 @@ For example, `pages/shop/[...slug].js` will match `/shop/clothes`, but also `/sh

## Optional Catch-all Segments

Catch-all Segments can be made **optional** by including the parameter in double square brackets: `[[...folderName]]`.
Catch-all Segments can be made **optional** by including the parameter in double square brackets: `[[...segmentName]]`.

For example, `pages/shop/[[...slug]].js` will **also** match `/shop`, in addition to `/shop/clothes`, `/shop/clothes/tops`, `/shop/clothes/tops/t-shirts`.

Expand Down

0 comments on commit c8064d6

Please sign in to comment.