Kết quả được trả về ctx.render(arg) của handler sẽ được truyền lại vào props.data của component

Fresh takes whatever you pass into ctx.render(arg) and sets it on props.data. There is no code to ensure that it is correct or anything. It just passes it along. If nothing is passed to ctx.render() then props.data will be undefined

import { Handlers, PageProps } from "$fresh/server.ts"
export const handler: Handlers = {
    GET(req, ctx) {
        return ctx.render({req}) 
    }
}
export default function App(props: PageProps){
    return <h1>
        {props.data.req.url} 
    </h1>
} 

Route cần có ít nhất một handler hoặc một component. Props là đối số đầu tiên của hàm component, dùng để truyền giá trị các thuộc tính của nó


Cập nhật lần cuối : 30 tháng 6, 2024
Tạo : 20 tháng 4, 2024