docs: fix some issues (#294)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
989e1775a0
commit
0d0a137d6e
@@ -3,10 +3,10 @@ description: |
|
|||||||
Error pages can be used to customize the page that is shown when an error occurs in the application.
|
Error pages can be used to customize the page that is shown when an error occurs in the application.
|
||||||
---
|
---
|
||||||
|
|
||||||
Fresh supports customizing the 404 Not Found, and the 500 Internal Server Error
|
Fresh supports customizing the `404 Not Found`, and the
|
||||||
pages. These are shown when a request is made but no matching route exists, and
|
`500 Internal Server Error` pages. These are shown when a request is made but no
|
||||||
when a middelware, route handler, or page component throws an error
|
matching route exists, and when a middelware, route handler, or page component
|
||||||
respectively.
|
throws an error respectively.
|
||||||
|
|
||||||
The 404 page can be customized by creating a `_404.tsx` file in the `routes/`
|
The 404 page can be customized by creating a `_404.tsx` file in the `routes/`
|
||||||
folder. The file must have a default export that is a regular Preact component.
|
folder. The file must have a default export that is a regular Preact component.
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export default function MyIsland() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
An island can be used in a page like a regular preact component. Fresh will take
|
An island can be used in a page like a regular Preact component. Fresh will take
|
||||||
care of automatically re-hydrating the island on the client.
|
care of automatically re-hydrating the island on the client.
|
||||||
|
|
||||||
Passing props to islands is supported, but only if the props are JSON
|
Passing props to islands is supported, but only if the props are JSON
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ The handler is a function that is called for every request to the route. It
|
|||||||
needs to return a response that is then sent to the client. The response could
|
needs to return a response that is then sent to the client. The response could
|
||||||
be anything: a plain text string, a JSON object, an HTML page, a WebSocket
|
be anything: a plain text string, a JSON object, an HTML page, a WebSocket
|
||||||
connection, a streaming file, or pretty much anything else. The handler is
|
connection, a streaming file, or pretty much anything else. The handler is
|
||||||
passed a `render` function that it can call to invoke rendering the component.
|
passed a `render` function that it can call to invoke rendering a component.
|
||||||
|
|
||||||
The component is the template for a page. It is a JSX element that is rendered
|
The component is the template for a page. It is a JSX element that is rendered
|
||||||
on the server. The page component gets passed props that can be used by it to
|
on the server. The page component gets passed props that can be used by it to
|
||||||
determine exactly what should be rendered. By default the request URL, the
|
determine exactly what should be rendered. By default components receives props
|
||||||
matches from the URL pattern match, and any data passed to the handler's
|
consisting of: the request URL, the matches from the URL pattern match, and any
|
||||||
`render` function are passed to the component as props.
|
data passed to the handler's `render` function.
|
||||||
|
|
||||||
Let's look at a basic route that returns a plain text string:
|
Let's look at a basic route that returns a plain text string:
|
||||||
|
|
||||||
@@ -38,9 +38,10 @@ To define a handler, one needs to export a `handler` function or object from the
|
|||||||
route module. If the handler is an object, each key in the object is the name of
|
route module. If the handler is an object, each key in the object is the name of
|
||||||
the HTTP method that the handler should be called for. For example the `GET`
|
the HTTP method that the handler should be called for. For example the `GET`
|
||||||
handler above is called for `GET` requests. If the handler is a function, it is
|
handler above is called for `GET` requests. If the handler is a function, it is
|
||||||
called for all requests regardless of the method.
|
called for all requests regardless of the method. If a HTTP method does not have
|
||||||
|
a corresponding handler, a 405 HTTP error is returned.
|
||||||
|
|
||||||
Now, let's render some HTML using the route component. Another example:
|
Now, let's render some HTML using the route component:
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// routes/html.tsx
|
// routes/html.tsx
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
> TODO(lucacasonato): this page still needs to be completed
|
|
||||||
|
|
||||||
Fresh automatically serves static assets placed in a `static/` directory in the
|
Fresh automatically serves static assets placed in a `static/` directory in the
|
||||||
project root. These assets are served at the root of the webserver, with a
|
project root. These assets are served at the root of the webserver, with a
|
||||||
higher priority than routes. This means that if a given request matches a file
|
higher priority than routes. This means that if a given request matches a file
|
||||||
|
|||||||
Reference in New Issue
Block a user