Pulse

Routing

Routes, layouts, and client routing components

Route definitions and client-side navigation components.

Classes

Route

Represents a route definition with its component and children.

Constructor

def __init__(
    self,
    path: str,
    render: Component[[]],
    children: Sequence[Route | Layout] | None = None,
    dev: bool = False,
)

Parameters:

  • path - Route path (relative, no leading slash). Use :param for dynamic segments, ? suffix for optional, * for catch-all.
  • render - Component to render for this route.
  • children - Nested routes and layouts (optional).
  • dev - If True, route only exists in dev environment.

Attributes

AttributeTypeDescription
pathstrNormalized relative path
segmentslist[PathSegment]Parsed path segments
renderComponent[[]]Route component
childrenSequence[Route | Layout]Child routes/layouts
is_indexboolTrue if path is empty (index route)
is_dynamicboolTrue if path has dynamic segments
devboolDev-only flag
parentRoute | Layout | NoneParent route or layout

Methods

unique_path
def unique_path(self) -> str

Return absolute path with leading /.

default_route_info
def default_route_info(self) -> RouteInfo

Return default RouteInfo for static routes.

Raises: InvalidRouteError if route or ancestors have dynamic segments.

import pulse as ps

app = ps.App(
    routes=[
        ps.Route("", Home),
        ps.Route("users", Users, children=[
            ps.Route(":id", UserDetail),
        ]),
        ps.Route("files/*", FileViewer),
        ps.Route("admin", AdminPanel, dev=True),
    ]
)

Layout

Wraps child routes with a shared layout component.

Constructor

def __init__(
    self,
    render: Component[...],
    children: Sequence[Route | Layout] | None = None,
    dev: bool = False,
)

Parameters:

  • render - Layout component (must render Outlet for children).
  • children - Routes and nested layouts.
  • dev - If True, layout only exists in dev environment.

Attributes

AttributeTypeDescription
renderComponent[...]Layout component
childrenSequence[Route | Layout]Child routes/layouts
devboolDev-only flag
parentRoute | Layout | NoneParent route or layout
import pulse as ps

@ps.component
def DashboardLayout():
    return ps.div(
        Sidebar(),
        ps.main(ps.Outlet()),
    )

app = ps.App(
    routes=[
        ps.Layout(DashboardLayout, children=[
            ps.Route("dashboard", Dashboard),
            ps.Route("settings", Settings),
        ]),
    ]
)

RouteInfo

TypedDict containing route information from the client.

class RouteInfo(TypedDict):
    pathname: str       # Current URL path
    hash: str           # URL hash (without #)
    query: str          # Query string (without ?)
    queryParams: dict[str, str]  # Parsed query parameters
    pathParams: dict[str, str]   # Dynamic path parameters
    catchall: list[str]          # Catch-all segments

RouteContext

Runtime context for the current route, accessible via ps.route().

Attributes

AttributeTypeDescription
infoRouteInfoCurrent route info (reactive)
pulse_routeRoute | LayoutRoute/layout definition

Properties

@property
def pathname(self) -> str: ...

@property
def hash(self) -> str: ...

@property
def query(self) -> str: ...

@property
def queryParams(self) -> dict[str, str]: ...

@property
def pathParams(self) -> dict[str, str]: ...

@property
def catchall(self) -> list[str]: ...

Components

Client-side navigation link (wraps react-router Link).

def Link(
    *children: Node,
    key: str | None = None,
    to: str,
    discover: Literal["render", "none"] | None = None,
    prefetch: Literal["none", "intent", "render", "viewport"] = "intent",
    preventScrollReset: bool | None = None,
    relative: Literal["route", "path"] | None = None,
    reloadDocument: bool | None = None,
    replace: bool | None = None,
    state: dict[str, object] | None = None,
    viewTransition: bool | None = None,
    **props: HTMLAnchorProps,
)

Parameters:

  • to - Target path.
  • prefetch - Prefetch strategy. Default: "intent".
  • replace - Replace history entry instead of push.
  • state - State to pass to the target route.
  • **props - Additional anchor element props.
ps.Link("Go Home", to="/")
ps.Link("User", to="/users/123", prefetch="render")

Outlet

Renders child routes within a layout (wraps react-router Outlet).

def Outlet(key: str | None = None)
@ps.component
def AppLayout():
    return ps.div(
        Header(),
        ps.Outlet(),  # Child routes render here
        Footer(),
    )

Functions

Programmatic navigation (available via ps.navigate()).

def navigate(path: str) -> None

Parameters:

  • path - Target path.
def handle_submit():
    # ... save data ...
    ps.navigate("/success")

route

Get current route context (available via ps.route()).

def route() -> RouteContext

Returns: Current RouteContext.

@ps.component
def UserProfile():
    ctx = ps.route()
    user_id = ctx.pathParams.get("id")
    return ps.div(f"User: {user_id}")

Path Syntax

PatternExampleDescription
StaticusersExact match
Dynamic:idNamed parameter
Optional:id?Optional parameter
Catch-all*Match remaining segments

Exceptions

InvalidRouteError

class InvalidRouteError(Exception)

Raised for invalid route configurations (empty segments, invalid characters, misplaced catch-all).

On this page