Skip to content

Route Registry

Source: ui/route_registry.py

Declarative route definitions that connect paths with factories, wrappers, layout strategies, chrome, and fallback behavior. See the Routing concept for narrative and examples.

Declarative registry of route factories, layouts, wrappers, and chrome.

Public surface for authors and maintainers:

  • Enums RouteKind, BodyWrapperKind, and LayoutKind classify routes.
  • RouteDef describes one registered route.
  • ROUTE_REGISTRY is the authoritative ordered tuple of route definitions.
  • get_route looks up a RouteDef by path.
  • build_drawer_controls builds drawer destinations from shell routes.
  • DRAWER_ROUTES, DEEP_ROUTES, and KNOWN_ROUTES expose path lists.

RouteKind

Bases: Enum

Describe how a route participates in the page view stack.

Attributes:

Name Type Description
SHELL

Root destination that replaces the current view stack.

DEEP

Destination that may be pushed above a shell view.

Source code in src/learning_app/ui/route_registry.py
class RouteKind(Enum):
    """Describe how a route participates in the page view stack.

    Attributes:
        SHELL: Root destination that replaces the current view stack.
        DEEP: Destination that may be pushed above a shell view.
    """

    SHELL = "shell"
    DEEP = "deep"

BodyWrapperKind

Bases: Enum

Select the host wrapper applied to route body controls.

Attributes:

Name Type Description
SHELL

Width-constrained shell column without an added safe area.

BOTTOM_INSET_SHELL

Shell column protected from side and bottom intrusions while allowing the app bar to own the top inset.

DEEP

Width-constrained form container for a deep route.

Source code in src/learning_app/ui/route_registry.py
class BodyWrapperKind(Enum):
    """Select the host wrapper applied to route body controls.

    Attributes:
        SHELL: Width-constrained shell column without an added safe area.
        BOTTOM_INSET_SHELL: Shell column protected from side and bottom
            intrusions while allowing the app bar to own the top inset.
        DEEP: Width-constrained form container for a deep route.
    """

    SHELL = "shell"
    BOTTOM_INSET_SHELL = "bottom_inset_shell"
    DEEP = "deep"

LayoutKind

Bases: Enum

Select the resize-layout strategy for a route.

Attributes:

Name Type Description
HOME

Refresh the home tile collection's flex layout.

IMPORT_EXPORT

Apply routable shell sizing to import/export content.

SHELL

Apply shell sizing to the route's declared layout control.

DEEP_FORM

Apply form sizing to a routable deep-screen control.

Source code in src/learning_app/ui/route_registry.py
class LayoutKind(Enum):
    """Select the resize-layout strategy for a route.

    Attributes:
        HOME: Refresh the home tile collection's flex layout.
        IMPORT_EXPORT: Apply routable shell sizing to import/export content.
        SHELL: Apply shell sizing to the route's declared layout control.
        DEEP_FORM: Apply form sizing to a routable deep-screen control.
    """

    HOME = "home"
    IMPORT_EXPORT = "import_export"
    SHELL = "shell"
    DEEP_FORM = "deep_form"

RouteDef dataclass

Describe all routing and presentation behavior for one route.

Attributes:

Name Type Description
path str

Canonical route path without query parameters.

kind RouteKind

Whether the route replaces the shell or is pushed as a deep view.

body_wrapper BodyWrapperKind

Wrapper used to host controls returned by the factory.

layout_kind LayoutKind

Layout strategy applied initially and after resize events.

chrome ShellChromeConfig | None

Shared shell chrome configuration, or None for deep routes.

build_factory RouteBuildFactory

Callable that builds body controls from a page and decoded route parameters. Returning None triggers fallback.

body_content_alignment MainAxisAlignment

Main-axis alignment inside deep body columns.

vertical_alignment MainAxisAlignment

Main-axis alignment assigned to the Flet view.

shell_layout_control type | None

Optional control type used to identify the routable shell body during layout updates.

drawer_label str | None

Navigation drawer label, or None to omit the route.

drawer_icon str | None

Name of the corresponding ft.Icons member.

drawer_divider_before bool

Whether to add a divider before this drawer item.

fallback_path str | None

Route used when the body factory returns None.

Source code in src/learning_app/ui/route_registry.py
@dataclass(frozen=True)
class RouteDef:
    """Describe all routing and presentation behavior for one route.

    Attributes:
        path: Canonical route path without query parameters.
        kind: Whether the route replaces the shell or is pushed as a deep view.
        body_wrapper: Wrapper used to host controls returned by the factory.
        layout_kind: Layout strategy applied initially and after resize events.
        chrome: Shared shell chrome configuration, or ``None`` for deep routes.
        build_factory: Callable that builds body controls from a page and
            decoded route parameters. Returning ``None`` triggers fallback.
        body_content_alignment: Main-axis alignment inside deep body columns.
        vertical_alignment: Main-axis alignment assigned to the Flet view.
        shell_layout_control: Optional control type used to identify the
            routable shell body during layout updates.
        drawer_label: Navigation drawer label, or ``None`` to omit the route.
        drawer_icon: Name of the corresponding ``ft.Icons`` member.
        drawer_divider_before: Whether to add a divider before this drawer item.
        fallback_path: Route used when the body factory returns ``None``.
    """

    path: str
    kind: RouteKind
    body_wrapper: BodyWrapperKind
    layout_kind: LayoutKind
    chrome: ShellChromeConfig | None
    build_factory: RouteBuildFactory
    body_content_alignment: ft.MainAxisAlignment = ft.MainAxisAlignment.START
    vertical_alignment: ft.MainAxisAlignment = ft.MainAxisAlignment.START
    shell_layout_control: type | None = None
    drawer_label: str | None = None
    drawer_icon: str | None = None
    drawer_divider_before: bool = False
    fallback_path: str | None = None

build_drawer_controls

build_drawer_controls() -> list[Control]

Build drawer destinations from registered drawer routes.

Returns:

Type Description
list[Control]

A spacer followed by registered destinations and configured dividers.

Source code in src/learning_app/ui/route_registry.py
def build_drawer_controls() -> list[ft.Control]:
    """Build drawer destinations from registered drawer routes.

    Returns:
        A spacer followed by registered destinations and configured dividers.
    """
    controls: list[ft.Control] = [ft.Container(height=24)]
    for route in DRAWER_ROUTE_DEFS:
        if route.drawer_divider_before:
            controls.append(ft.Divider(thickness=2))
        controls.append(
            ft.NavigationDrawerDestination(
                label=route.drawer_label,
                icon=_drawer_icon(route.drawer_icon),
            )
        )
    return controls

get_route

get_route(path: str) -> RouteDef | None

Look up a route definition by canonical path.

Parameters:

Name Type Description Default
path str

Route path without query parameters.

required

Returns:

Type Description
RouteDef | None

The matching route definition, or None when the path is unknown.

Source code in src/learning_app/ui/route_registry.py
def get_route(path: str) -> RouteDef | None:
    """Look up a route definition by canonical path.

    Args:
        path: Route path without query parameters.

    Returns:
        The matching route definition, or ``None`` when the path is unknown.
    """
    return ROUTES_BY_PATH.get(path)