import { createFileRoute, Link } from '@tanstack/react-router' import { strapiApi } from '@/data/loaders' import { StrapiImage } from '@/components/strapi-image' import { BlockRenderer } from '@/components/blocks' import type { TArticle } from '@/types/strapi' export const Route = createFileRoute('/demo/strapi/$articleId')({ component: RouteComponent, errorComponent: ErrorComponent, loader: async ({ params }) => { try { const response = await strapiApi.articles.getArticleByIdData({ data: params.articleId, }) return { success: true, article: response.data } } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to load article', article: null, } } }, }) function ErrorComponent({ error }: { error: Error }) { return (
← Back to Articles

Error Loading Article

{error.message}

) } function RouteComponent() { const { success, article, error } = Route.useLoaderData() as { success: boolean article: TArticle | null error?: string } // Show error state if (!success || !article) { return (
Back to Articles

{error || 'Article Not Found'}

Make sure the Strapi server is running and the article exists.

) } return (
Back to Articles

{article.title || 'Untitled'}

{article.author?.name && ( By{' '} {article.author.name} )} {article.createdAt && ( {new Date(article.createdAt).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', })} )}
{article.category?.name && (
{article.category.name}
)} {article.description && (

{article.description}

)} {article.blocks && article.blocks.length > 0 && ( )}
) }