Skip to content

Commit 7bb4d70

Browse files
KianNHWalshyDev
andauthored
[Pages] Use FileTree component in Functions routing (#17448)
* [Pages] Use FileTree component in Functions routing * Update src/content/docs/pages/functions/routing.mdx * Update src/content/docs/pages/functions/routing.mdx --------- Co-authored-by: Daniel Walsh <[email protected]>
1 parent 15ec733 commit 7bb4d70

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

src/content/docs/pages/functions/routing.mdx

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ pcx_content_type: reference
33
title: Routing
44
sidebar:
55
order: 2
6-
76
---
87

8+
import { FileTree } from "~/components";
9+
910
Functions utilize file-based routing. Your `/functions` directory structure determines the designated routes that your Functions will run on. You can create a `/functions` directory with as many levels as needed for your project's use case. Review the following directory:
1011

11-
```
12-
|---- …
13-
|---- functions
14-
|___ index.js
15-
|___ helloworld.js
16-
|___ howdyworld.js
17-
|___ fruits
18-
|___ index.js
19-
|___ apple.js
20-
|___ banana.js
21-
```
12+
<FileTree>
13+
- ...
14+
- functions
15+
- index.js
16+
- helloworld.js
17+
- howdyworld.js
18+
- fruits
19+
- index.js
20+
- apple.js
21+
- banana.js
22+
</FileTree>
2223

2324
The following routes will be generated based on the above file structure. These routes map the URL pattern to the `/functions` file that will be invoked when a visitor goes to the URL:
2425

@@ -33,10 +34,8 @@ The following routes will be generated based on the above file structure. These
3334

3435
:::note[Trailing slash]
3536

36-
3737
Trailing slash is optional. Both `/foo` and `/foo/` will be routed to `/functions/foo.js` or `/functions/foo/index.js`. If your project has both a `/functions/foo.js` and `/functions/foo/index.js` file, `/foo` and `/foo/` would route to `/functions/foo/index.js`.
3838

39-
4039
:::
4140

4241
If no Function is matched, it will fall back to a static asset if there is one. Otherwise, the Function will fall back to the [default routing behavior](/pages/configuration/serving-pages/) for Pages' static assets.
@@ -72,25 +71,23 @@ By placing two sets of brackets around your filename – for example, `/users/[[
7271

7372
:::note[Route specificity]
7473

75-
7674
More specific routes (routes with fewer wildcards) take precedence over less specific routes.
7775

78-
7976
:::
8077

8178
#### Dynamic route examples
8279

8380
Review the following `/functions/` directory structure:
8481

85-
```
86-
|---- …
87-
|---- functions
88-
|___ date.js
89-
|___ users/
90-
|___ special.js
91-
|___ [user].js
92-
|___ [[catchall]].js
93-
```
82+
<FileTree>
83+
- ...
84+
- functions
85+
- date.js
86+
- users
87+
- special.js
88+
- [user].js
89+
- [[catchall]].js
90+
</FileTree>
9491

9592
The following requests will match the following files:
9693

@@ -131,10 +128,8 @@ On a purely static project, Pages offers unlimited free requests. However, once
131128

132129
:::note
133130

134-
135131
Some frameworks (such as Remix, SvelteKit) will also automatically generate a `_routes.json` file. However, if your preferred framework does not, create an issue on their framework repository with a link to this page or let us know on [Discord](https://discord.cloudflare.com). Refer to the [Framework guide](/pages/framework-guides/) for more information on full-stack frameworks.
136132

137-
138133
:::
139134

140135
### Create a `_routes.json` file
@@ -149,10 +144,8 @@ This file will include three different properties:
149144

150145
:::note
151146

152-
153147
Wildcards match any number of path segments (slashes). For example, `/users/*` will match everything after the`/users/` path.
154148

155-
156149
:::
157150

158151
#### Example configuration

0 commit comments

Comments
 (0)