← Navigation and routes

Navigation.RouteCompiler

luastra/navigation

Navigation.RouteCompiler is a stateful navigation contract that owns route history or translates between route entries and canonical locations. Its public methods validate mutations and return bounded results instead of exposing internal tables.

Before you use it

Add luastra/navigation to this module's dependencies in luastra.json, then import it with require("luastra/navigation"). No host capability is required for in-memory navigation. Browser URL/history synchronization additionally needs luastra/host and navigation.history.

How it fits

The type describes a route, stack, compiler, or checked result used by navigation operations.

When to use it

Use Navigation.RouteCompiler as long-lived application state when navigation must survive repeated renders. Create it once, mutate it through its public methods, and render from its current route rather than rebuilding it on every render.

Fields or definition

ParameterType / valuesDescription
match(location: string) -> RouteResultCallable match member exposed by Navigation.RouteCompiler; invoke it through the owning contract rather than replacing internal state.
generate(entry: any) -> RouteResultCallable generate member exposed by Navigation.RouteCompiler; invoke it through the owning contract rather than replacing internal state.
canonicalize(location: string) -> RouteResultCallable canonicalize member exposed by Navigation.RouteCompiler; invoke it through the owning contract rather than replacing internal state.

What happens next

A checked route/navigation annotation.

Failures and fixes

Invalid definitions, unknown routes, malformed parameters, excessive history depth, or incompatible snapshots return bounded errors or fail construction. Navigation result records use success:boolean with optional fields, so verify the field you need after checking success.

Availability

Public-source alpha API in 0.5.0-alpha; URL integration is a separate host capability.

Exact declaration

export type RouteCompiler = {
    match: (location: string) -> RouteResult,
    generate: (entry: any) -> RouteResult,
    canonicalize: (location: string) -> RouteResult,
}

Continue learning

Companions

Navigation.RouteEntryNavigation.EntryStackNavigation.createRouter

Next steps

Navigation.compile

Complete inventory

View all pages in Navigation and routes
← Previous: Navigation.RouteResultNext: Navigation.EntrySnapshot →