useStatamicPage

Gitlab
A composable for fetching Statamic page data.
Added since: v1.0.0
Last changed:

Usage

The useStatamicPage composable is used to fetch Statamic page data.

Fetching the correct page is done by fetching the entry with the same URI as the current route. The URI is derived from the useStatamicPageUri composable.

This composable will also set the page state (useState) whenever the page data is fetched.

You can optionally pass a custom URI to the composable to fetch a different page.

Basic example

Do note that we also use the useStatamicPageErrorHandler composable to handle the error.
pages/[...slug].vue
<script setup lang="ts">
const { 
data
,
error
} = await
useStatamicPage
();
useStatamicPageErrorHandler
(
error
);
</script>

Type Definition

function 
useStatamicPage
<
T
extends
Record
<string, any> =
StatamicApiEntryDefaultFields
>(
options
?: {
uri
?: string;
fetchOptions
?:
AsyncDataOptions
<
T
>;
}, ):
AsyncData
<
T
,
NuxtError
>

API Reference

Params

The URI of the page to fetch
options.fetchOptions
AsyncDataOptions<T>
AsyncData options.

Return Value

AsyncData<T, NuxtError>
Returns a fully configured useAsyncData composable.

Will throw a 404 error if the page is not found, this needs to be handled by the useStatamicPageErrorHandler composable afterwards.

Changelog

v1.0.1

on

#95765ee3

-

improvement: `useStatamicPageData` cachekey now matches `useStatamicPage`

#2bfba18c

-

fix: useStatamicPage now correctly sets the page state

v1.0.0

on

#407d36db

-

feat: released initial version of nuxt-statamic