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

docs: add dynamic routes page #219

Merged
merged 6 commits into from
Dec 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ import Breadcrumbs, { Element } from '@/components/breadcrumbs'

> 🚧 Only available for SSR apps. This feature will be soon available also for static generated apps.

When you don't know the exact segment names ahead of time and
want to create routes from dynamic data, you can use
Dynamic Segments that are filled in at request time.
When the exact segment names are not known in advance and you need to generate routes from dynamic data,
you can use dynamic segments, which are populated at request time.

## Convention

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

## Example
You are going to probably use something like:
Valerioageno marked this conversation as resolved.
Show resolved Hide resolved

For example, a blog could include the following route `src/routes/blog/[slug].tsx`
where [slug] is the Dynamic Segment for blog posts.
- `[id]`
- `[slug]`

### Example

Assuming you're working on a blog with multiple posts,
you can use a dynamic segment to define the post page: `src/routes/blog/[slug].tsx`.

The `[slug]` is the dynamic segment which will be used to identify individual blog posts.

```tsx
import { useRouter } from 'tuono'
Expand All @@ -41,5 +47,11 @@ export default function Page() {
Dynamic Segments can be extended to catch-all subsequent segments by adding
an ellipsis inside the brackets `[...segmentName]`.

For example, `src/routes/shop/[...slug].tsx` will match `/shop/clothes`,
but also `/shop/clothes/tops`, `/shop`, `/shop/clothes/tops/t-shirts`, and so on.
Given the following `src/routes/shop/[...slug].tsx`,
the following paths will be matched:

- `/shop/clothes`
- `/shop/clothes/tops`
- `/shop`
- `/shop/clothes/tops/t-shirts`
- and so on.
Loading