# Entry pages

Give a collection a path and each entry gets its own URL. The entry page is the component that renders one entry there.

## The path

`path` on a collection is the URL segment its entries live under. The starter's articles sit at `/posts/<slug>` in English and `/artikkelit/<slug>` in Finnish:

File: `smoodly/collections.ts`

```ts
export const articles = smoodly.collection({
  name: "articles",
  title: "Articles",
  titleField: "title",
  path: { en: "posts", fi: "artikkelit" },
  order: { by: "date", direction: "desc" },
  fields: {
    title: f.text().localized(),
    image: f.image({ aspect: "3:2" }),
    date: f.date(),
    author: f.ref(() => people),
    slug: f.slug({ from: "title" }),
    excerpt: f.text().localized(),
    // …
  },
});
```

A string applies to every language; an object names the segment per language. The collection needs a field named `slug` for the entry's own part. A collection without a `path` has no URLs: its entries appear only through references and queries.

The path shows in the page tree as a mount, so editors see where the entries live. Pages cannot be created under it.

## A nested path

A path may have several parts. The starter's news sits under the company, at `/company/news/<slug>` and `/yritys/uutiset/<slug>` in Finnish:

File: `smoodly/collections.ts`

```ts
export const news = smoodly.collection({
  name: "news",
  title: "News",
  titleField: "title",
  path: { en: "company/news", fi: "yritys/uutiset" },
  order: { by: "date", direction: "desc" },
  // …
});
```

Your code owns the whole address, not just its last part. The *Company* page at `/company` is an editor's page, or no page at all: renaming or moving it never moves the news, because published URLs should not change with an easy rename in the admin. The page tree lists the collection at the root with its full URL, and editors cannot put a page on `/company/news` or under it.

Each part follows the slug rule. A language the map leaves out takes the default language's address.

Change the path in code and the URLs of the index page and every entry change when the deploy goes live: Smoodly stores only each entry's own part, never the address. The old URLs stop working, so add a redirect in `next.config.ts` for them, as [Paths and slugs](https://smoodly.io/docs/pages/paths-and-slugs.md#redirects) shows.

## The entry page

**Astro**

A collection with a `path` needs an entry page: `src/entry-pages/<collection>.astro`, named after the collection. It receives `entry` and `head`:

File: `src/entry-pages/articles.astro`

```astro
---
// …
const { entry, head } = Astro.props;
const { locale, locales } = entry;
// …
const a = entry.fields;
// …
const { entries: newest = [] } = await getLiveCollection("articles", { locale, limit: 4 });
// …
---
<Layout head={head} locale={locale} locales={locales}>
  <article class="container article">
    // …
      <h1 class="article__title">{a.title}</h1>
    // …
    {a.image && <Image image={a.image} aspect="21:9" class="article__image" sizes="(min-width: 900px) 800px, 100vw" priority />}
    <div class="article__body prose prose--lead"><RichText doc={a.body} sizes="(min-width: 900px) 720px, 100vw" /></div>
  </article>
  // …
</Layout>
```

The entry's `fields` are resolved: images are ready for `Image`, and a reference such as `author` is `{ id, path, fields }`, the person's fields under `fields`. Beside `fields` the entry carries its `id`, `path`, `locale`, the language rendered, and `locales`, which maps every language to the entry's address there, for a language switcher, and `seo` when the collection turns [SEO](https://smoodly.io/docs/pages/seo.md#seo-for-entries) on. `head` goes to the layout's `Head`.

There is nothing to register: the file is the entry page. A collection with a `path` and no file is named in the server log at the first request, and its entries answer 404.

**Next.js**

A collection with a `path` needs an entry page, or the site stops at the first render and names the collection. `smoodly.entryPage()` pairs the collection with a component. An entry page has no schema of its own, so it is listed in `pages` in `smoodly/views.ts`, not in the config:

File: `components/pages/Article.tsx`

```tsx
import { smoodly } from "smoodly/react";
import { RichText } from "@/smoodly/richtext";
import { SmoodlyImage } from "smoodly/image";
import { articles } from "@/smoodly/collections";
// …
export const ArticlePage = smoodly.entryPage(articles, async function ArticleView({ entry }) {
  const { locale, locales } = entry;
  // …
  const a = entry.fields;
  // …
  return (
    <PageFrame locale={locale} locales={locales}>
      <article className="container article">
        // …
          <h1 className="article__title">{a.title}</h1>
        // …
        {a.image && <SmoodlyImage image={a.image} aspect="21:9" className="article__image" sizes="(min-width: 900px) 800px, 100vw" priority />}
        <div className="article__body prose prose--lead"><RichText doc={a.body} /></div>
      </article>
      // …
    </PageFrame>
  );
});
```

The view receives `entry`, whose `fields` are resolved: images are ready for `SmoodlyImage`, and a reference such as `author` is `{ id, path, fields }`, the person's fields under `fields`. Beside `fields` the entry carries its `id`, `path`, `locale`, the language rendered, and `locales`, which maps every language to the entry's address there, for a language switcher, and `seo` when the collection turns [SEO](https://smoodly.io/docs/pages/seo.md#seo-for-entries) on. Register the export in the `pages` list of `smoodly/config.ts`, beside the page types.

An entry page has no zones. It is your own markup over the entry's fields, and editors change the entry in its form rather than in a canvas.

## The index page

The list at `/posts` itself is an ordinary fixed page whose slug matches the collection's path in every language:

File: `components/pages/Articles.schema.ts`

```ts
export const articlesSchema = smoodly.schema.page({
  name: "articlesIndex",
  title: "Articles",
  slug: { en: "posts", fi: "artikkelit" },
  zones: {
    hero: z.locked(pageHeroSchema),
  },
  seo: true,
});
```

Its view and its registration are any page type's (see [Page types](https://smoodly.io/docs/content-modeling/page-types.md)), with the schema listed in `pages` in the config.

**Astro**

The view is `src/page-types/articlesIndex.astro`.

**Next.js**

The view is `export const ArticlesPage = smoodly.page(articlesSchema, ArticlesView)`, listed in `pages` in `smoodly/views.ts`.

The list page is live as soon as you deploy it, with an empty hero until an editor fills it. Its row appears in *Pages* the next time someone opens the admin.

Because the slugs match, that page is the mount: the row in the page tree opens its editor, editors own its hero, and its view queries the entries for the grid below. [Queries](https://smoodly.io/docs/collections/queries.md) shows that part. A nested path works the same way: the News index page's slug is `{ en: "company/news", fi: "yritys/uutiset" }`.

**Astro**

Nothing changes in the routes: the integration's page shell already resolves a URL to a page, a path or an entry, and renders an entry with its collection's entry page.

**Next.js**

Nothing changes in the routes: the catch-all route already resolves a URL to a page, a path or an entry, and renders an entry with its collection's entry page.

Next, [Queries](https://smoodly.io/docs/collections/queries.md).
