← Navigation and routes

Navigation.compile

luastra/navigation
Navigation.compile(definitionsValue: any): RouteCompiler

Compiles route definitions into a RouteCompiler that generates canonical locations and matches incoming path and query strings back to typed route entries. Invalid definitions and malformed locations produce bounded route errors.

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 operation updates or creates application-owned navigation state synchronously. Keep stacks and compilers outside app.render, inspect every result.success field, then render from the accepted current entry.

When to use it

Use Navigation.compile once at module initialization when web URLs or deep links must share one source of truth with application routes. Generate links through the compiler and validate incoming locations before changing the navigation stack.

Parameters

ParameterType / valuesDescription
definitionsValueanyDense route-definition array containing unique names and canonical path templates.

Returns

RouteCompiler — a reusable compiler for matching, generating, and canonicalizing admitted route locations.

What happens next

A validated compiler, stack, decision, or result record; host history changes only when the application requests them separately.

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.

Focused example

local Navigation = require("luastra/navigation")
local compiler = Navigation.compile {
    { name = "home", path = "/" },
    { name = "card", path = "/card/:id" },
}

Continue learning

Prerequisites

Navigation.RouteCompiler

Companions

Navigation.RouteEntryNavigation.EntryStack

Complete inventory

View all pages in Navigation and routes
← Previous: Navigation.createRouter