Enhanced navigation
The product page already renders at /products/42. Start with product links in a catalogue or in a list of related products. With atom:navigate, the Atom client follows the link and updates the main content while the shared header and footer stay in place.
Enable enhanced navigation
Put atom:navigate on an ordinary link. The href still gives the browser a URL it can open directly or follow when JavaScript is disabled.
<ul>
<li><a href="/products/42" atom:navigate>Desk lamp</a></li>
<li><a href="/products/43" atom:navigate>Floor lamp</a></li>
</ul>
When a shopper selects Desk lamp, the Atom client fetches /products/42 with a GET request. The server handles the request as usual. It matches ProductPage, calls get("42"), and returns the rendered page. The client applies the new HTML and updates the browser URL.
Update Root
Mark the part of the shared layout that displays each page's content. Atom Starter already puts atom:update-root on <main>. Keep the shared header and footer outside it.
<main id="main" atom:update-root>
{{ $context->fragmentHtml($this->content) }}
</main>
With this layout on both pages, Atom takes the <main> from the product response and updates the current <main>. The catalogue gives way to the product name and its quantity controls, while the surrounding layout stays in place. The same boundary applies when a quantity action returns updated HTML.
If either document lacks atom:update-root, Atom falls back to updating <body>.
Browser history
Say the catalogue is at /products and the shopper selects Desk lamp. After applying the product response, Atom adds /products/42 to browser history.
When the shopper presses Back, the browser returns the address bar to /products and fires a popstate event. Atom fetches that URL again with a GET request and applies the returned catalogue HTML to the same update root. It also restores the catalogue's document title from the response. The header and footer stay in place, and Atom adds no history entry during this update, so Forward still leads to /products/42.
Back and Forward request fresh HTML from the server. For example, if the shopper returns to the product with Forward, ProductPage::get() loads the product again and the example's quantity starts at 1. If a history request fails, Atom reloads the current URL through the browser.
Client Scripts
The server renders the catalogue and product pages as complete HTML documents. The shared layout loads atom.js, which listens for enhanced links, forms, and actions. It sends the request, reads the response, and updates the document title and page state before handing the current and incoming content to the update engine.
Atom Starter includes the scripts near the end of its shared layout:
<ClientScripts morphdom />
ClientScripts loads the Atom client. The morphdom option also loads MorphDOM and the Atom adapter. The built-in engine replaces the selected content. With the adapter, MorphDOM compares the incoming HTML with the existing DOM and patches what changed. Both engines use the same atom:update-root boundary. The exit transitions below use the MorphDOM adapter.
Exit Transitions
Show a notice when the product quantity reaches its minimum. In the nested form example, add this after the quantity controls in ProductPage.atom.html.
@if($this->quantityForm->quantity === 1)
<p id="quantity-notice" atom:transition>Minimum quantity is 1.</p>
@endif
Add the fade to the stylesheet your layout loads. The selector applies the animation only while Atom is removing the notice.
#quantity-notice[data-atom-leaving] {
animation: quantity-notice-out 160ms ease-in both;
}
@keyframes quantity-notice-out {
to { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
#quantity-notice[data-atom-leaving] {
animation: none;
}
}
At quantity 1, the server renders the notice. Press + and the response shows 2 and omits it. When MorphDOM compares the current content with that response, the Atom adapter sees atom:transition and delays removal. It adds data-atom-leaving, makes the notice inert and hidden from assistive technology, then removes it when the fade finishes. The quantity can update while the notice fades.
The morphdom option in <ClientScripts morphdom /> loads the adapter that handles this lifecycle. With the built-in update engine, or when reduced motion disables the animation, the notice disappears immediately.