Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/content/docs/fr/reference/modules/astro-static-paths.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: Référence de l'API des chemins statiques
sidebar:
label: 'astro:static-paths'
i18nReady: true
tableOfContents:
minHeadingLevel: 2
maxHeadingLevel: 6
---
import ReadMore from '~/components/ReadMore.astro';
import Since from '~/components/Since.astro';

<p><Since v="6.0.0" /></p>

Ce module fournit des utilitaires pour aider les adaptateurs à collecter les chemins statiques depuis leur environnement d'exécution cible (par exemple, `workerd`). Il n'offre une implémentation fonctionnelle que dans l'environnement `prerender` de Vite. Dans les autres environnements, il renvoie une implémentation sans opération.

## Importations depuis `astro:static-paths`

```js
import {
StaticPaths,
} from 'astro:static-paths';
```

### `StaticPaths`

Permet aux adaptateurs de collecter tous les chemins qui doivent être pré-rendus à partir de leur environnement d'exécution cible. Ceci est utile lors de la [mise en œuvre d'un pré-rendu personnalisé](/fr/reference/adapter-reference/#custom-prerenderer) exécuté dans un environnement non-Node :

Check failure on line 27 in src/content/docs/fr/reference/modules/astro-static-paths.mdx

View workflow job for this annotation

GitHub Actions / Check Links

Broken fragment link in src/content/docs/fr/reference/modules/astro-static-paths.mdx, line 27: The linked page does not contain a fragment with the name "#custom-prerenderer". Available fragments: #theme-icons, #gradient, #starlight__sidebar, #__tab-démarrage, #__tab-guides-et-recettes, #__tab-référence, #__tab-intégrations, #__tab-services-tiers, #starlight__mobile-toc, #starlight__on-this-page--mobile, #starlight__on-this-page, #learn-astro-course-2, #_top, #quest-ce-quun-adaptateur-, #création-dun-adaptateur, #name, #serverentrypoint, #supportedastrofeatures, #adapterfeatures, #args, #client, #internalfetchheaders, #assetqueryparams, #exports, #previewentrypoint, #création-dun-point-dentrée-de-serveur, #createexports, #start, #astroapp, #apprender, #renderoptions, #addcookieheader, #clientaddress, #locals, #prerenderederrorpagefetch, #routedata, #appmatch, #appgetadapterlogger, #appgetalloweddomains, #appremovebase, #appsetcookieheaders, #appgetsetcookiefromresponse, #appvalidateforwardedhost, #appsanitizehost, #appvalidateforwardedheaders, #astroappnode, #nodeapprender, #nodeappmatch, #nodeappheadersmap, #nodeappsetheadersmap, #nodeappcreaterequest, #nodeappwriteresponse, #fonctionnalités-dastro, #staticoutput, #hybridoutput, #serveroutput, #i18ndomains, #envgetsecret, #sharpimageservice, #fonctionnalités-de-ladaptateur, #edgemiddleware, #buildoutput, #experimentalstaticheaders, #référence-des-types-des-adaptateurs, #adaptersupport, #adaptersupportskind, #adaptersupportwithmessage, #support, #message, #suppress, #autoriser-linstallation-via-astro-add, #docsearch-lvl0, #learn-astro-course-1

Le constructeur `StaticPaths` accepte un [manifeste SSR](/en/reference/integrations-reference/#ssrmanifest) obligatoire et un objet décrivant le cache de routes et fournissant une méthode d'accès au composant utilisé pour le rendu de la route. La méthode préférée pour initialiser une instance `StaticPaths` consiste à lui passer une [instance d'application](/fr/reference/modules/astro-app/#linstance-app).

Check failure on line 29 in src/content/docs/fr/reference/modules/astro-static-paths.mdx

View workflow job for this annotation

GitHub Actions / Check Links

Link to unexpected language in src/content/docs/fr/reference/modules/astro-static-paths.mdx, line 29: Expected link path to start with "/fr/", but found "/en/". The correct prefix is required to ensure that users stay on their selected language version of the docs. Suggested fix: /fr/reference/integrations-reference/#ssrmanifest

Check failure on line 29 in src/content/docs/fr/reference/modules/astro-static-paths.mdx

View workflow job for this annotation

GitHub Actions / Check Links

Broken fragment link in src/content/docs/fr/reference/modules/astro-static-paths.mdx, line 29: The linked page does not contain a fragment with the name "#linstance-app". Available fragments: #theme-icons, #gradient, #starlight__sidebar, #__tab-démarrage, #__tab-guides-et-recettes, #__tab-référence, #__tab-intégrations, #__tab-services-tiers, #starlight__mobile-toc, #starlight__on-this-page--mobile, #starlight__on-this-page, #learn-astro-course-2, #_top, #imports-from-astroappentrypoint, #createapp, #options, #optionsstreaming, #the-app-instance, #apprender, #appmatch, #appgetadapterlogger, #appgetalloweddomains, #appremovebase, #appsetcookieheaders, #imports-from-astroappnode, #createrequest, #writeresponse, #astroapp-types, #renderoptions, #renderoptionsaddcookieheader, #renderoptionsclientaddress, #renderoptionslocals, #renderoptionsprerenderederrorpagefetch, #renderoptionsroutedata, #docsearch-lvl0, #learn-astro-course-1

L'exemple suivant initialise une instance `StaticPaths` à partir d'une application dans un point d'entrée de serveur d'adaptateur :

```js title="my-adapter/server.js"
import { createApp } from 'astro/app/entrypoint';
import { StaticPaths } from 'astro:static-paths';

const app = createApp();
const staticPaths = new StaticPaths(app);

export const handler = (event, context) => {
// faire quelque chose avec `staticPaths`
};
```

#### `StaticPaths.getAll()`

<p>

**Type :** <code>() => Promise\<Array\<\{ pathname: string, route: <a href="/fr/reference/integrations-reference/#routedata">RouteData</a> \}\>\></code>
</p>

Récupère tous les chemins qui doivent être pré-rendus. Cette fonction renvoie une promesse qui se résout en un tableau d'objets décrivant le chemin de la route et ses données.

L'exemple suivant collecte tous les chemins statiques à pré-générer avant de les renvoyer en tant que `Response` dans un gestionnaire d'adaptateur :

```js title="my-adapter/handler.js"
import { StaticPaths } from 'astro:static-paths';

export function createHandler(app) {
return async (request) => {
const { pathname } = new URL(request.url);

// Point de terminaison pour collecter les chemins statiques lors de la compilation
if (pathname === '/__astro_static_paths') {
const staticPaths = new StaticPaths(app);
const paths = await staticPaths.getAll();
// Renvoie un tableau de { pathname: string, route: RouteData }
return new Response(JSON.stringify({ paths }));
}

// ... traiter d'autres requêtes
};
}
```
Loading