diff --git a/docs/concepts/architechture.md b/docs/concepts/architechture.md index 86e8c7f4..2758f121 100644 --- a/docs/concepts/architechture.md +++ b/docs/concepts/architechture.md @@ -1 +1,26 @@ -> TODO(lucacasonato): this page still needs to be written +--- +description: | + Fresh's architechture is designed to make it easy to build fast, scalable, and reliable applications. +--- + +Fresh is designed to makes it easy to build fast, scalable, and reliable +applications. To do this, it makes opinionated decisions about how one should +build web applications. These decisions are backed by strong emperial data +gathered from experts in the field. Some examples of these principles are: + +- Page load times should be reduced to a minimum. +- The work performed on the client should be minimized. +- Errors should have a small blast radius - stuff should gracefully degrade. + +The single biggest architechture decision that Fresh makes is it's usage of the +[islands architecture][islands] pattern. This means that Fresh applications ship +pure HTML to the client by default. Parts of server rendered page can then be +independently re-hydrated with interactive widgets (islands). This means that +the client is only responsible for rendering parts of the page that are +interactive enough to warrant the extra effort. Any content that is purely +static does not have related client side JavaScript, and is thus very +lightweight. + + + +[islands]: https://www.patterns.dev/posts/islands-architecture/ diff --git a/docs/concepts/index.md b/docs/concepts/index.md index 86e8c7f4..a1cb240c 100644 --- a/docs/concepts/index.md +++ b/docs/concepts/index.md @@ -1 +1,8 @@ -> TODO(lucacasonato): this page still needs to be written +--- +description: | + This chapter goes over some fundamental concepts of Fresh. +--- + +This chapter goes over some fundamental concepts of Fresh. It covers the +overarching architecture design of Fresh applications, as well as reference +documentation about the various features of Fresh. diff --git a/docs/concepts/routes.md b/docs/concepts/routes.md index 26eb99cc..e93df999 100644 --- a/docs/concepts/routes.md +++ b/docs/concepts/routes.md @@ -1,5 +1,3 @@ -> TODO(lucacasonato): complete this page - At it's core, routes describe how a request for a given path should be handled, and what the response should be. To do this, routes have two main parts: the handler, and the component. A route can have either one, or both, but never diff --git a/docs/concepts/routing.md b/docs/concepts/routing.md index 86e8c7f4..96ca5d2a 100644 --- a/docs/concepts/routing.md +++ b/docs/concepts/routing.md @@ -1 +1,56 @@ -> TODO(lucacasonato): this page still needs to be written +--- +description: | + File based routing is the simplest way to do routing in Fresh apps. Additionally custom patterns can be configured per route. +--- + +Routing is the mechanism that determines what route a given incoming request is +handled by. Fresh routes requests based on their URL path. By default routes +specify which paths they are invoked for using the name of the file. Routes can +also define a custom [URL pattern][urlpattern] to match against for more +advanced use cases. + +The file based routing in Fresh is very similar to the file based routing seen +in other frameworks, namely Next.js. File names are used to determine which +route a given request should be handled by. The pattern is determined based on +the path of the file on disk, relative to the `routes/` directory. + +File names are mapped to route patterns as follows: + +- File extensions are ignored. +- Literals in the file path are treated as string literals to match. +- Files named `/index.` behave identically to a file named + `.`. +- Path segments can be made dynamic by surrounding an identifier with `[` and + `]`. +- Paths where the last path segment follows the structure `[...]` are + treated as having a wildcard suffix. + +Here is a table of file names, and which route patterns they map to, and which +paths they might match: + +| File name | Route pattern | Matching paths | +| ------------------------- | ---------------------- | -------------------------- | +| `index.ts` | `/` | `/` | +| `about.ts` | `/about` | `/about` | +| `blog/index.ts` | `/blog` | `/blog` | +| `blog/[slug].ts` | `/blog/:slug` | `/blog/foo`, `/blog/bar` | +| `blog/[slug]/comments.ts` | `/blog/:slug/comments` | `/blog/foo/comments` | +| `old/[...path].ts` | `/old/:path*` | `/old/foo`, `/old/bar/baz` | + +Advanced use-cases can require that a more complex pattern be used for matching. +A custom [URL pattern][urlpattern] can be specified in the route configuration. +This pattern will be used instead of the file path based pattern: + +```ts +// routes/x.ts + +import { RouteConfig } from "$fresh/runtime.ts"; + +const config: RouteConfig = { + routeOverride: "/x/:module@:version/:path*", +}; + +// ... +``` + +[urlpattern]: https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API