Pages

Pages are specialized components that serve as entry points for different routes in your Hologram application. Together with regular components, they form the fundamental building blocks of Hologram applications. They inherit all the capabilities of components, including templates, state management, actions, commands, and event handling. For detailed information about these shared features, see the Components documentation.

Key Differences from Regular Components

While pages are built on top of components, they have some unique characteristics:

Basic Example

Here's a minimal page implementation:

defmodule MyApp.HelloWorldPage do
  use Hologram.Page
  
  route "/hello-world"
  
  layout MyApp.MainLayout

  def template do
    ~HOLO"""
    <div>Hello World!</div>
    """
  end
end

Routing and Parameters

Pages must define their URL route using the route/1 macro.

Routes can be static:

route "/products"

or contain dynamic parameters:

route "/users/:username/posts/:post_id/comments"

For routes with parameters, use the param/2 macro to specify how string parameters should be converted:

param :username, :string
param :post_id, :integer

Supported parameter types:

Component ID

The page is always assigned a component ID (cid) of "page". This is important to remember when targeting actions or commands at the page.

Previous
← Components