Hi, I just started tinkering with Astro and Typescript(and frontend in general...) and have a question stated in the title.
Code:
Head element with title(required) and description(not):
---
export interface HeadProps { (#1)
title: string;
description?: string;
}
const { title, description = "Default Page Description" } = Astro.props as HeadProps;
---
<head>
...
<title>{title}</title>
<meta name="description" content={description} />
</head>
Base layout that uses head element:
---
import type { HeadProps } from "@components/BaseHead.astro";
import BaseHead from "@components/BaseHead.astro";
export interface Props extends HeadProps {}; (#2)
const props = Astro.props as Props; (#3)
---
<html lang="en">
<BaseHead {...props} />
<slot>
<p>Default Layout</p>
</slot>
</html>
Index page that uses BaseLayout and passes title down:
---
import BaseLayout from "@layouts/BaseLayout.astro";
---
<BaseLayout title="Index Page">Index Page</BaseLayout> (#4)
(1/2)