Skip to content

Commit

Permalink
docs(routing): escape filename paths and prepend routes folder (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkronborg committed Jan 19, 2024
1 parent 0551d96 commit 7d3ca94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/content/1.guide/3.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ You do not need to import `defineEventHandler` as it is automatically imported t

To define a route with params, use the `[<param>]` syntax where `<param>` is the name of the param. The param will be available in the `event.context.params` object or using the `getRouteParam` utility from [unjs/h3](https://h3.unjs.io).

```ts [/hello/[name].ts]
```ts [/routes/hello/[name\\].ts]
export default defineEventHandler(event => {
const name = getRouteParam(event, 'name')

Expand All @@ -71,7 +71,7 @@ Hello nitro!

You can define multiple params in a route using `[<param1>]/[<param2>]` syntax where each param is a folder. You **cannot** define multiple params in a single filename of folder.

```ts [/hello/[name]/[age].ts]
```ts [/routes/hello/[name\\]/[age\\].ts]
export default defineEventHandler(event => {
const name = getRouteParam(event, 'name')
const age = getRouteParam(event, 'age')
Expand All @@ -84,7 +84,7 @@ export default defineEventHandler(event => {

You can capture all the remaining parts of a URL using `[...<param>]` syntax. This will include the `/` in the param.

```ts [/hello/[...name].ts]
```ts [/routes/hello/[...name\\].ts]
export default defineEventHandler(event => {
const name = getRouteParam(event, 'name')

Expand Down Expand Up @@ -134,7 +134,7 @@ You can create a special route that will match all routes that are not matched b

To create a catch all route, create a file named `[...].ts` in the `routes/` or `api/` directory or in any subdirectory.

```ts [/routes/[...].ts]
```ts [/routes/[...\\].ts]
export default defineEventHandler(event => {
const url = getRequestURL(event)

Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.guide/5.cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const cachedGHStars = definedCachedFunction(async (repo: string) => {
getKey: (repo: string) => repo
})
```
```ts [api/stars/[...repo].ts]
```ts [api/stars/[...repo\\].ts]
export default defineEventHandler(async (event) => {
const repo = event.context.params.repo
const stars = await cachedGHStars(repo).catch(() => 0)
Expand Down

0 comments on commit 7d3ca94

Please sign in to comment.