Pages and layouts
Pages
A page is a component in pages/, named by the path the server sends: Users/Show is pages/Users/Show.gts. It gets its props as @props, since Glimmer can't spread arguments into a component:
// pages/Users/Show.gts
import type { TOC } from '@ember/component/template-only';
import { Link, type PageSignature } from 'inertia-ember';
export default <template>
<h1>{{@props.user.name}}</h1>
<Link @href='/users'>Back</Link>
</template> satisfies TOC<PageSignature<{ user: User }>>;A page that needs state is a class component:
import Component from '@glimmer/component';
import type { PageSignature } from 'inertia-ember';
export default class Show extends Component<PageSignature<{ user: User }>> {
get greeting() {
return `Hello, ${this.args.props.user.name}`;
}
<template>
<h1>{{this.greeting}}</h1>
</template>
}Layouts
A layout gets @props too (the page's props, plus whatever setLayoutProps set) and yields the page. Layouts stay mounted while you move between pages that share them, so their state survives visits.
import Component from '@glimmer/component';
import { Link, type LayoutSignature } from 'inertia-ember';
export default class AppLayout extends Component<LayoutSignature> {
<template>
<nav><Link @href='/'>Home</Link></nav>
<main>{{yield}}</main>
</template>
}createInertiaApp({ layout }) sets the default. A page picks its own layout, or a list of nested ones, by exporting layout:
export const layout = AdminLayout;
export const layout = [AppLayout, AdminLayout];
export const layout = (props) => (props.user.admin ? AdminLayout : AppLayout);The demo's layout keeps a clock that counts from when it mounted, so you can see it survive navigation.
Try it ↗ , and read its source.The current page
page (or usePage()) is the current page, and it's tracked, so templates and getters update when it changes:
import { page } from 'inertia-ember';
page.props.auth.user;
page.url;
page.component;
page.flash.toast;Head
<Head> sets the title and tags in the document head, on the server too:
<Head @title='{{@props.post.title}}'>
<meta name='description' content={{@props.post.excerpt}} head-key='description' />
</Head>head-key keeps one tag per key, so a page's description replaces the layout's. The title goes through the title callback you gave createInertiaApp.
Errors
An Inertia server renders an error page like any other, with a status. The demo renders Error for unknown URLs:
import type { TOC } from '@ember/component/template-only';
import { Link, type PageSignature } from 'inertia-ember';
type Props = { error: { status: number; message: string } };
export default <template>
<div class='mx-auto max-w-md py-16 text-center'>
<p class='font-mono text-6xl font-semibold text-[#e04e39]' data-test-status>{{@props.error.status}}</p>
<h1 class='mt-4 text-2xl font-semibold'>{{@props.error.message}}</h1>
<p class='mt-2 text-stone-600'>Laravel Rust rendered this error through the Inertia <code>Error</code> page.</p>
<Link @href='/' class='mt-8 inline-block rounded-lg bg-stone-900 px-4 py-2 text-sm font-medium text-white'>Back home</Link>
</div>
</template> satisfies TOC<PageSignature<Props>>;