docs: fix misleading main.tsx filenames (#3477)
Closes #3476 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Bartek Iwańczuk
Claude Opus 4.6
parent
be467d3cdb
commit
420a8cfb8e
@@ -47,7 +47,7 @@ export default define.page(({ Component, url }) => {
|
|||||||
|
|
||||||
When building your app with `new App()` instead of file-based routing:
|
When building your app with `new App()` instead of file-based routing:
|
||||||
|
|
||||||
```tsx main.tsx
|
```tsx
|
||||||
function AppWrapper({ Component }) {
|
function AppWrapper({ Component }) {
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ Fresh supports two kind of error pages:
|
|||||||
To add an error page use [`app.onError()`](/docs/concepts/app#onerror).
|
To add an error page use [`app.onError()`](/docs/concepts/app#onerror).
|
||||||
|
|
||||||
```ts main.ts
|
```ts main.ts
|
||||||
|
import { App } from "fresh";
|
||||||
|
|
||||||
const app = new App()
|
const app = new App()
|
||||||
.onError("*", (ctx) => {
|
.onError("*", (ctx) => {
|
||||||
console.log(`Error: ${ctx.error}`);
|
console.log(`Error: ${ctx.error}`);
|
||||||
@@ -36,7 +38,7 @@ will be invoked.
|
|||||||
|
|
||||||
You can also nest error pages:
|
You can also nest error pages:
|
||||||
|
|
||||||
```ts main.ts
|
```ts
|
||||||
const app = new App()
|
const app = new App()
|
||||||
// Top level error page
|
// Top level error page
|
||||||
.onError("*", (ctx) => {
|
.onError("*", (ctx) => {
|
||||||
@@ -56,7 +58,7 @@ Not found errors are often treated differently than generic errors. You can both
|
|||||||
treat them with the `.onError()` way, but by adding a specific `.notFound()`
|
treat them with the `.onError()` way, but by adding a specific `.notFound()`
|
||||||
handler, Fresh ensures that every 404 error will invoke this callback.
|
handler, Fresh ensures that every 404 error will invoke this callback.
|
||||||
|
|
||||||
```ts main.ts
|
```ts
|
||||||
const app = new App()
|
const app = new App()
|
||||||
// Top level error page
|
// Top level error page
|
||||||
.notFound((ctx) => {
|
.notFound((ctx) => {
|
||||||
@@ -103,7 +105,7 @@ async function authMiddleware(ctx) {
|
|||||||
When an `HttpError` is thrown, Fresh catches it and invokes the error handler.
|
When an `HttpError` is thrown, Fresh catches it and invokes the error handler.
|
||||||
You can check the status code in your error handler:
|
You can check the status code in your error handler:
|
||||||
|
|
||||||
```ts main.ts
|
```ts
|
||||||
import { HttpError } from "fresh";
|
import { HttpError } from "fresh";
|
||||||
|
|
||||||
app.onError("*", (ctx) => {
|
app.onError("*", (ctx) => {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ HTML structure and only the content changes, a layout is a neat way to abstract
|
|||||||
this. Layouts only ever render on the server. The passed `Component` value
|
this. Layouts only ever render on the server. The passed `Component` value
|
||||||
represents the children of this component.
|
represents the children of this component.
|
||||||
|
|
||||||
```tsx main.tsx
|
```tsx
|
||||||
function PageLayout({ Component }) {
|
function PageLayout({ Component }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -42,7 +42,7 @@ You can register multiple layouts for different paths. Layouts are inherited
|
|||||||
from parent paths - a layout at `"*"` applies to all routes, and more specific
|
from parent paths - a layout at `"*"` applies to all routes, and more specific
|
||||||
layouts are added on top:
|
layouts are added on top:
|
||||||
|
|
||||||
```ts main.ts
|
```ts
|
||||||
const app = new App()
|
const app = new App()
|
||||||
.layout("*", MainLayout) // Applied to all routes
|
.layout("*", MainLayout) // Applied to all routes
|
||||||
.layout("/admin/*", AdminLayout) // Added on top for /admin/* routes
|
.layout("/admin/*", AdminLayout) // Added on top for /admin/* routes
|
||||||
@@ -69,6 +69,6 @@ const app = new App()
|
|||||||
|
|
||||||
Ignore the [app wrapper](/docs/concepts/app) component:
|
Ignore the [app wrapper](/docs/concepts/app) component:
|
||||||
|
|
||||||
```ts main.ts
|
```ts
|
||||||
app.layout("/foo/bar", MyComponent, { skipAppWrapper: true });
|
app.layout("/foo/bar", MyComponent, { skipAppWrapper: true });
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ mounted alongside other apps. The base path is available in handlers via
|
|||||||
All items are applied from top to bottom. This means that when you defined a
|
All items are applied from top to bottom. This means that when you defined a
|
||||||
middleware _after_ a `.get()` handler, it won't be included.
|
middleware _after_ a `.get()` handler, it won't be included.
|
||||||
|
|
||||||
```ts main.ts
|
```ts
|
||||||
const app = new App()
|
const app = new App()
|
||||||
.use((ctx) => {
|
.use((ctx) => {
|
||||||
// Will be called for all middlewares
|
// Will be called for all middlewares
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ Routing defines which middlewares and routes should respond to a particular
|
|||||||
request.
|
request.
|
||||||
|
|
||||||
```ts main.ts
|
```ts main.ts
|
||||||
|
import { App } from "fresh";
|
||||||
|
|
||||||
const app = new App()
|
const app = new App()
|
||||||
.get("/", () => new Response("hello")) // Responds to: GET /
|
.get("/", () => new Response("hello")) // Responds to: GET /
|
||||||
.get("/other", () => new Response("other")) // Responds to: GET /other
|
.get("/other", () => new Response("other")) // Responds to: GET /other
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ once in your build output.
|
|||||||
By default, Fresh adds caching headers for the `src` and `srcset` attributes on
|
By default, Fresh adds caching headers for the `src` and `srcset` attributes on
|
||||||
`<img>` and `<source>` tags.
|
`<img>` and `<source>` tags.
|
||||||
|
|
||||||
```tsx main.tsx
|
```ts
|
||||||
// Caching headers will be automatically added
|
// Caching headers will be automatically added
|
||||||
app.get("/user", (ctx) => ctx.render(<img src="/user.png" />));
|
app.get("/user", (ctx) => ctx.render(<img src="/user.png" />));
|
||||||
```
|
```
|
||||||
@@ -60,7 +60,7 @@ app.get("/user", (ctx) => ctx.render(<img src="/user.png" />));
|
|||||||
You can always opt out of this behaviour per tag, by adding the
|
You can always opt out of this behaviour per tag, by adding the
|
||||||
`data-fresh-disable-lock` attribute.
|
`data-fresh-disable-lock` attribute.
|
||||||
|
|
||||||
```tsx main.tsx
|
```ts
|
||||||
// Opt-out of automatic caching headers
|
// Opt-out of automatic caching headers
|
||||||
app.get(
|
app.get(
|
||||||
"/user",
|
"/user",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Fresh is a small, fast and extensible full stack web framework built on Web
|
|||||||
Standards. It's designed for building high-quality, performant, and personalized
|
Standards. It's designed for building high-quality, performant, and personalized
|
||||||
web applications.
|
web applications.
|
||||||
|
|
||||||
```tsx main.tsx
|
```tsx main.ts
|
||||||
import { App } from "fresh";
|
import { App } from "fresh";
|
||||||
|
|
||||||
const app = new App()
|
const app = new App()
|
||||||
|
|||||||
Reference in New Issue
Block a user