diff --git a/docs/examples/changing-the-src-dir.md b/docs/examples/changing-the-src-dir.md index f4501d7b..e7f29903 100644 --- a/docs/examples/changing-the-src-dir.md +++ b/docs/examples/changing-the-src-dir.md @@ -18,9 +18,11 @@ you'll end up with a project like the following: │ └── Counter.tsx ├── main.ts ├── routes -│ ├── [name].tsx +│ ├── greet +│ │ ├── [name].tsx │ ├── api │ │ └── joke.ts +│ ├── _404.tsx │ └── index.tsx └── static ├── favicon.ico @@ -64,9 +66,11 @@ The resulting file structure looks like this: │ └── Counter.tsx ├── main.ts ├── routes - │ ├── [name].tsx + │ ├── greet + │ │ ├── [name].tsx │ ├── api │ │ └── joke.ts + │ ├── _404.tsx │ └── index.tsx └── static ├── favicon.ico diff --git a/docs/getting-started/dynamic-routes.md b/docs/getting-started/dynamic-routes.md index e5f4d50d..df15a1fb 100644 --- a/docs/getting-started/dynamic-routes.md +++ b/docs/getting-started/dynamic-routes.md @@ -1,31 +1,31 @@ --- description: | Create a dynamic route in fresh by adding a dynamic segment to the route name - in the routes' file name on disk: `/[name].tsx`. + in the routes' file name on disk: `/greet/[name].tsx`. --- The `/about` route created on the last page is pretty static. It does not matter what query or path parameters are passed to the route, it will always render the -same page. Let's create a `/:name` that will render a page with a greeting that -contains the name passed in the path. +same page. Let's create a `/greet/:name` that will render a page with a greeting +that contains the name passed in the path. Before diving in, a quick refresher on "dynamic" routes. Dynamic routes don't just match a single static path, but rather a whole bunch of different paths -based on a pattern. For example, the `/:name` route will match the paths `/Luca` -and `/John`, but not `/Luca/John`. +based on a pattern. For example, the `/greet/:name` route will match the paths +`/greet/Luca` and `/John`, but not `/greet/Luca/John`. Fresh supports dynamic routes out of the box through file system routing. To make any path segment dynamic, just put square brackets around that segment in -the file name. For example the `/:name` route maps to the file name -`routes/[name].tsx`. +the file name. For example the `/greet/:name` route maps to the file name +`routes/greet/[name].tsx`. -Just like the static `/about` route, the dynamic `/:name` route will render a -page. The module must once again expose a component as a default export. This -time the component will receive the matched path segment properties as arguments -in its `props` object though. +Just like the static `/about` route, the dynamic `/greet/:name` route will +render a page. The module must once again expose a component as a default +export. This time the component will receive the matched path segment properties +as arguments in its `props` object though. ```tsx -// routes/[name].tsx +// routes/greet/[name].tsx import { PageProps } from "$fresh/server.ts"; @@ -43,7 +43,7 @@ The `PageProps` interface actually contains a bunch of useful properties that can be used to customize the rendered output. Next to the matched url pattern parameters, the raw `url`, and the `route` name can also be found in here. -Navigating to `http://localhost:8000/Luca` will now render a page showing +Navigating to `http://localhost:8000/greet/Luca` will now render a page showing "Greetings to you, Luca!". The [_Concepts: Routing_][concepts-routing] page has more information about diff --git a/init.ts b/init.ts index 3c88b04f..3220d7ed 100644 --- a/init.ts +++ b/init.ts @@ -189,11 +189,50 @@ export default function Greet(props: PageProps) { return