routing

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Overview

Package routing provides file-based routing similar to SvelteKit. It scans .templ files in a routes directory and maps them to URLs.

Package routing provides component registry for route handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildURL

func BuildURL(pattern string, pathParams Params, queryParams *QueryParams) string

BuildURL builds a URL from a route pattern and parameters.

func HasLayout

func HasLayout(path string) bool

HasLayout checks if a layout is registered in the global registry.

func HasPage

func HasPage(path string) bool

HasPage checks if a page is registered in the global registry.

func RegisterLayout

func RegisterLayout(path string, fn LayoutFunc)

RegisterLayout registers a layout component in the global registry.

func RegisterPage

func RegisterPage(path string, fn ComponentFunc)

RegisterPage registers a page component in the global registry (default SSR).

func RegisterPageWithOptions

func RegisterPageWithOptions(path string, fn ComponentFunc, opts RouteOptions)

RegisterPageWithOptions registers a page in the global registry with options.

func RegisterRemoteAction

func RegisterRemoteAction(name string, action RemoteActionFunc)

RegisterRemoteAction registers a remote server function.

func RegisterRootLayout

func RegisterRootLayout(fn LayoutFunc)

RegisterRootLayout registers the root layout in the global registry.

func RegisterSlot added in v0.1.4

func RegisterSlot(pagePath, slotName string, fn SlotFunc)

RegisterSlot registers a PPR dynamic slot in the global registry.

func ValidateParams

func ValidateParams(route *Route, params Params) error

ValidateParams validates route parameters against a route.

Types

type ComponentFunc

type ComponentFunc func(props map[string]interface{}) templ.Component

ComponentFunc is a function that returns a templ.Component.

func GetPage

func GetPage(path string) ComponentFunc

GetPage returns the page component from the global registry.

type Handler

type Handler func(c *fiberpkg.Ctx) error

Handler is a generic HTTP handler function.

type LayoutChain

type LayoutChain struct {
	// Layouts are ordered from root to leaf
	Layouts []*Route
	// Page is the final page route
	Page *Route
	// Error is the error route for this chain
	Error *Route
}

LayoutChain represents a chain of nested layouts.

func (*LayoutChain) String

func (lc *LayoutChain) String() string

String returns a string representation of the layout chain.

type LayoutContext

type LayoutContext struct {
	// Path is the current URL path
	Path string
	// Params are the route parameters
	Params map[string]string
	// Data is the layout data chain
	Data []*LayoutData
	// Depth is the current layout depth
	Depth int
}

LayoutContext provides context for layout rendering.

func NewLayoutContext

func NewLayoutContext(path string, params map[string]string) *LayoutContext

NewLayoutContext creates a new layout context.

func (*LayoutContext) CurrentData

func (lc *LayoutContext) CurrentData() *LayoutData

CurrentData returns the current layout data.

func (*LayoutContext) PopData

func (lc *LayoutContext) PopData() *LayoutData

PopData pops layout data from the chain.

func (*LayoutContext) PushData

func (lc *LayoutContext) PushData(data *LayoutData)

PushData pushes new layout data onto the chain.

type LayoutData

type LayoutData struct {
	// Data is the layout data
	Data map[string]interface{}
	// Children is nested content
	Children interface{}
}

LayoutData represents data passed through layouts.

func NewLayoutData

func NewLayoutData() *LayoutData

NewLayoutData creates new layout data.

func (*LayoutData) Get

func (ld *LayoutData) Get(key string) (interface{}, bool)

Get gets a value from layout data.

func (*LayoutData) Merge

func (ld *LayoutData) Merge(other *LayoutData)

Merge merges another layout data into this one.

func (*LayoutData) Set

func (ld *LayoutData) Set(key string, value interface{})

Set sets a value in layout data.

type LayoutFunc

type LayoutFunc func(children templ.Component, props map[string]interface{}) templ.Component

LayoutFunc is a function that returns a templ.Component for layouts.

func GetLayout

func GetLayout(path string) LayoutFunc

GetLayout returns the layout component from the global registry.

func GetRootLayout

func GetRootLayout() LayoutFunc

GetRootLayout returns the root layout from the global registry.

type LayoutNode

type LayoutNode struct {
	Route    *Route
	Children []*LayoutNode
	Parent   *LayoutNode
}

LayoutNode represents a node in the layout tree.

type LayoutResolver

type LayoutResolver struct {
	// contains filtered or unexported fields
}

LayoutResolver resolves layout hierarchies for routes.

func NewLayoutResolver

func NewLayoutResolver() *LayoutResolver

NewLayoutResolver creates a new layout resolver.

func (*LayoutResolver) RegisterError

func (lr *LayoutResolver) RegisterError(route *Route)

RegisterError registers an error route.

func (*LayoutResolver) RegisterLayout

func (lr *LayoutResolver) RegisterLayout(route *Route)

RegisterLayout registers a layout route.

func (*LayoutResolver) ResolveChain

func (lr *LayoutResolver) ResolveChain(page *Route) *LayoutChain

ResolveChain resolves the layout chain for a page route.

type LayoutTree

type LayoutTree struct {
	Root *LayoutNode
}

LayoutTree represents a tree of layouts.

func NewLayoutTree

func NewLayoutTree(routes []*Route) *LayoutTree

NewLayoutTree creates a new layout tree from routes.

func (*LayoutTree) FindLayoutChain

func (t *LayoutTree) FindLayoutChain(path string) []*Route

FindLayoutChain finds the layout chain for a path.

type ManualRoute

type ManualRoute struct {
	// Path is the URL path pattern
	Path string
	// Method is the HTTP method (GET, POST, etc.)
	Method string
	// Handler is the route handler
	Handler Handler
	// Component is the Templ component (for page routes)
	Component templ.Component
	// Middleware is the route-specific middleware
	Middleware []Middleware
	// Params are the parameter names
	Params []string
	// IsDynamic indicates if the route has dynamic segments
	IsDynamic bool
	// Priority is used for route matching order
	Priority int
	// Meta contains route metadata
	Meta map[string]interface{}
}

ManualRoute represents a manually registered route.

func (*ManualRoute) GetMeta

func (r *ManualRoute) GetMeta(key string) (interface{}, bool)

GetMeta gets metadata from the route.

func (*ManualRoute) GetName

func (r *ManualRoute) GetName() string

GetName gets the route name.

func (*ManualRoute) Name

func (r *ManualRoute) Name(name string) *ManualRoute

Name sets a name for the route.

func (*ManualRoute) SetMeta

func (r *ManualRoute) SetMeta(key string, value interface{}) *ManualRoute

SetMeta sets metadata on the route.

func (*ManualRoute) String

func (r *ManualRoute) String() string

String returns a string representation of the route.

type ManualRouter

type ManualRouter struct {
	// contains filtered or unexported fields
}

ManualRouter manages manually registered routes.

func NewManualRouter

func NewManualRouter() *ManualRouter

NewManualRouter creates a new manual router.

func (*ManualRouter) DELETE

func (mr *ManualRouter) DELETE(path string, handler Handler, middleware ...Middleware) *ManualRoute

DELETE registers a DELETE route.

func (*ManualRouter) GET

func (mr *ManualRouter) GET(path string, handler Handler, middleware ...Middleware) *ManualRoute

GET registers a GET route.

func (*ManualRouter) GetRoutes

func (mr *ManualRouter) GetRoutes() []*ManualRoute

GetRoutes returns all manual routes.

func (*ManualRouter) Group

func (mr *ManualRouter) Group(prefix string, middleware ...Middleware) *RouteGroup

Group creates a new route group.

func (*ManualRouter) HEAD

func (mr *ManualRouter) HEAD(path string, handler Handler, middleware ...Middleware) *ManualRoute

HEAD registers a HEAD route.

func (*ManualRouter) Match

func (mr *ManualRouter) Match(method, path string) (*ManualRoute, Params)

Match matches a URL path and method to a route.

func (*ManualRouter) MatchAll

func (mr *ManualRouter) MatchAll(path string) []*ManualRoute

MatchAll returns all routes matching a path (for any method).

func (*ManualRouter) OPTIONS

func (mr *ManualRouter) OPTIONS(path string, handler Handler, middleware ...Middleware) *ManualRoute

OPTIONS registers an OPTIONS route.

func (*ManualRouter) PATCH

func (mr *ManualRouter) PATCH(path string, handler Handler, middleware ...Middleware) *ManualRoute

PATCH registers a PATCH route.

func (*ManualRouter) POST

func (mr *ManualRouter) POST(path string, handler Handler, middleware ...Middleware) *ManualRoute

POST registers a POST route.

func (*ManualRouter) PUT

func (mr *ManualRouter) PUT(path string, handler Handler, middleware ...Middleware) *ManualRoute

PUT registers a PUT route.

func (*ManualRouter) Page

func (mr *ManualRouter) Page(path string, component templ.Component, middleware ...Middleware) *ManualRoute

Page registers a Templ component as a page.

func (*ManualRouter) RegisterComponent

func (mr *ManualRouter) RegisterComponent(path string, component templ.Component, middleware ...Middleware) *ManualRoute

RegisterComponent registers a Templ component as a page route.

func (*ManualRouter) RegisterRoute

func (mr *ManualRouter) RegisterRoute(method, path string, handler Handler, middleware ...Middleware) *ManualRoute

RegisterRoute registers a manual route.

func (*ManualRouter) RegisterToFiber

func (mr *ManualRouter) RegisterToFiber(app *fiberpkg.App) error

RegisterToFiber registers all routes with a Fiber app.

func (*ManualRouter) SetAutoRouter

func (mr *ManualRouter) SetAutoRouter(router *Router)

SetAutoRouter sets the auto router for hybrid routing.

type Middleware

type Middleware func(c *fiberpkg.Ctx) error

Middleware is a Fiber middleware function.

type ParamExtractor

type ParamExtractor struct {
	// contains filtered or unexported fields
}

ParamExtractor extracts parameters from URLs.

func NewParamExtractor

func NewParamExtractor(pattern string) *ParamExtractor

NewParamExtractor creates a new parameter extractor for a pattern.

func (*ParamExtractor) Extract

func (pe *ParamExtractor) Extract(path string) (Params, bool)

Extract extracts parameters from a URL path.

func (*ParamExtractor) Match

func (pe *ParamExtractor) Match(path string) bool

Match checks if a path matches the pattern.

func (*ParamExtractor) Params

func (pe *ParamExtractor) Params() []string

Params returns the parameter names for this pattern.

type Params

type Params map[string]string

Params represents route parameters extracted from URL.

func ParamsFromJSON

func ParamsFromJSON(data []byte) (Params, error)

FromJSON creates Params from JSON.

func (Params) Bool

func (p Params) Bool(key string) (bool, error)

Bool returns a parameter as a bool.

func (Params) BoolOk added in v0.1.5

func (p Params) BoolOk(key string) (bool, bool, error)

BoolOk returns a parameter as a bool with an existence check.

func (Params) Clone

func (p Params) Clone() Params

Clone creates a copy of the params.

func (Params) Delete

func (p Params) Delete(key string)

Delete removes a parameter.

func (Params) Float64

func (p Params) Float64(key string) (float64, error)

Float64 returns a parameter as a float64.

func (Params) Float64Ok added in v0.1.5

func (p Params) Float64Ok(key string) (float64, bool, error)

Float64Ok returns a parameter as a float64 with an existence check.

func (Params) Get

func (p Params) Get(key string) string

Get returns a parameter value by key.

func (Params) GetDefault

func (p Params) GetDefault(key, defaultValue string) string

GetDefault returns a parameter value with a default.

func (Params) Has

func (p Params) Has(key string) bool

Has checks if a parameter exists.

func (Params) Int

func (p Params) Int(key string) (int, error)

Int returns a parameter as an int. Returns error if the parameter doesn't exist or cannot be parsed.

func (Params) Int64

func (p Params) Int64(key string) (int64, error)

Int64 returns a parameter as an int64.

func (Params) Int64Ok added in v0.1.5

func (p Params) Int64Ok(key string) (int64, bool, error)

Int64Ok returns a parameter as an int64 with an existence check.

func (Params) IntDefault

func (p Params) IntDefault(key string, defaultValue int) int

IntDefault returns a parameter as an int with a default. Returns defaultValue if the parameter doesn't exist or cannot be parsed.

func (Params) IntOk added in v0.1.5

func (p Params) IntOk(key string) (int, bool, error)

IntOk returns a parameter as an int with an existence check. Returns (value, true, nil) if found and valid. Returns (0, false, nil) if not found. Returns (0, true, error) if found but invalid.

func (Params) Merge

func (p Params) Merge(other Params)

Merge merges another Params into this one.

func (Params) Set

func (p Params) Set(key, value string)

Set sets a parameter value.

func (Params) Slice

func (p Params) Slice(key string) []string

Slice returns a parameter as a slice (for catch-all params).

func (Params) ToJSON

func (p Params) ToJSON() ([]byte, error)

ToJSON converts Params to JSON.

func (Params) ToMap

func (p Params) ToMap() map[string]string

ToMap converts Params to a regular map.

type PathBuilder

type PathBuilder struct {
	// contains filtered or unexported fields
}

PathBuilder helps build paths with parameters.

func NewPathBuilder

func NewPathBuilder(pattern string) *PathBuilder

NewPathBuilder creates a new path builder.

func (*PathBuilder) Build

func (pb *PathBuilder) Build() string

Build builds the final URL.

func (*PathBuilder) Param

func (pb *PathBuilder) Param(key, value string) *PathBuilder

Param sets a path parameter.

func (*PathBuilder) Query

func (pb *PathBuilder) Query(key, value string) *PathBuilder

Query sets a query parameter.

func (*PathBuilder) QueryAdd

func (pb *PathBuilder) QueryAdd(key, value string) *PathBuilder

QueryAdd adds a query parameter.

type QueryParams

type QueryParams struct {
	// contains filtered or unexported fields
}

QueryParams represents URL query parameters.

func NewQueryParams

func NewQueryParams(query string) *QueryParams

NewQueryParams creates QueryParams from a URL query string.

func NewQueryParamsFromValues

func NewQueryParamsFromValues(values url.Values) *QueryParams

NewQueryParamsFromValues creates QueryParams from url.Values.

func (*QueryParams) Add

func (qp *QueryParams) Add(key, value string)

Add adds a value for a key.

func (*QueryParams) Bool

func (qp *QueryParams) Bool(key string) (bool, error)

Bool returns a query parameter as a bool.

func (*QueryParams) BoolDefault

func (qp *QueryParams) BoolDefault(key string, defaultValue bool) bool

BoolDefault returns a query parameter as a bool with a default.

func (*QueryParams) BoolOk added in v0.1.5

func (qp *QueryParams) BoolOk(key string) (bool, bool, error)

BoolOk returns a query parameter as a bool with an existence check.

func (*QueryParams) Del

func (qp *QueryParams) Del(key string)

Del deletes a key.

func (*QueryParams) Encode

func (qp *QueryParams) Encode() string

Encode encodes the query parameters to a string.

func (*QueryParams) Get

func (qp *QueryParams) Get(key string) string

Get returns the first value for a key.

func (*QueryParams) GetAll

func (qp *QueryParams) GetAll(key string) []string

GetAll returns all values for a key.

func (*QueryParams) Has

func (qp *QueryParams) Has(key string) bool

Has checks if a key exists.

func (*QueryParams) Int

func (qp *QueryParams) Int(key string) (int, error)

Int returns a query parameter as an int.

func (*QueryParams) IntDefault

func (qp *QueryParams) IntDefault(key string, defaultValue int) int

IntDefault returns a query parameter as an int with a default.

func (*QueryParams) IntOk added in v0.1.5

func (qp *QueryParams) IntOk(key string) (int, bool, error)

IntOk returns a query parameter as an int with an existence check.

func (*QueryParams) Set

func (qp *QueryParams) Set(key, value string)

Set sets a value for a key.

func (*QueryParams) ToMap

func (qp *QueryParams) ToMap() map[string][]string

ToMap converts to a regular map.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds registered page and layout components.

func GetGlobalRegistry

func GetGlobalRegistry() *Registry

GetGlobalRegistry returns the global registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new component registry.

func (*Registry) GetLayout

func (r *Registry) GetLayout(path string) LayoutFunc

GetLayout returns the layout component for a path.

func (*Registry) GetPage

func (r *Registry) GetPage(path string) ComponentFunc

GetPage returns the page component for a path.

func (*Registry) GetRootLayout

func (r *Registry) GetRootLayout() LayoutFunc

GetRootLayout returns the root layout component.

func (*Registry) GetRouteOptions

func (r *Registry) GetRouteOptions(path string) RouteOptions

GetRouteOptions returns the route options for a path.

func (*Registry) GetSlot added in v0.1.4

func (r *Registry) GetSlot(pagePath, slotName string) SlotFunc

GetSlot returns the SlotFunc for a named PPR slot on a page path.

func (*Registry) HasLayout

func (r *Registry) HasLayout(path string) bool

HasLayout checks if a layout is registered for a path.

func (*Registry) HasPage

func (r *Registry) HasPage(path string) bool

HasPage checks if a page is registered for a path.

func (*Registry) RegisterLayout

func (r *Registry) RegisterLayout(path string, fn LayoutFunc)

RegisterLayout registers a layout component for a route path.

func (*Registry) RegisterPage

func (r *Registry) RegisterPage(path string, fn ComponentFunc)

RegisterPage registers a page component for a route path (default to SSR).

func (*Registry) RegisterPageWithOptions

func (r *Registry) RegisterPageWithOptions(path string, fn ComponentFunc, opts RouteOptions)

RegisterPageWithOptions registers a page component with specific options.

func (*Registry) RegisterRootLayout

func (r *Registry) RegisterRootLayout(fn LayoutFunc)

RegisterRootLayout registers the root layout component.

func (*Registry) RegisterSlot added in v0.1.4

func (r *Registry) RegisterSlot(pagePath, slotName string, fn SlotFunc)

RegisterSlot registers a PPR dynamic slot component for a page path.

type RemoteActionFunc

type RemoteActionFunc func(ctx context.Context, input interface{}) (interface{}, error)

RemoteActionFunc is a type-safe server function that can be called remotely from the client.

func GetRemoteAction

func GetRemoteAction(name string) (RemoteActionFunc, bool)

GetRemoteAction retrieves a registered remote server function.

type RemoteRegistry

type RemoteRegistry struct {
	// contains filtered or unexported fields
}

type RenderStrategy

type RenderStrategy string

RenderStrategy defines how a page is rendered.

const (
	// StrategySSR renders fresh on every request (default).
	StrategySSR RenderStrategy = "ssr"
	// StrategySSG renders once and caches forever (FIFO eviction via SSGCacheMaxEntries).
	StrategySSG RenderStrategy = "ssg"
	// StrategyISR renders once, then revalidates in the background after RevalidateAfter elapses
	// (stale-while-revalidate). Requires CacheTemplates: true.
	StrategyISR RenderStrategy = "isr"
	// StrategyPPR renders a static shell once and streams only named DynamicSlots
	// per-request. Requires CacheTemplates: true.
	StrategyPPR RenderStrategy = "ppr"
)

type Route

type Route struct {
	// Path is the URL path pattern (e.g., /blog/:id)
	Path string
	// File is the absolute path to the .templ file
	File string
	// Type indicates the route type
	Type RouteType
	// Params are the extracted parameter names
	Params []string
	// IsDynamic indicates if the route has dynamic segments
	IsDynamic bool
	// IsCatchAll indicates if the route has a catch-all segment
	IsCatchAll bool
	// Priority is used for route matching order
	Priority int
	// Children are nested routes
	Children []*Route
	// Layout is the parent layout route
	Layout *Route
	// Middleware is the middleware chain for this route
	Middleware []string
	// contains filtered or unexported fields
}

Route represents a parsed route from the filesystem.

func (*Route) RouteRegex

func (r *Route) RouteRegex() *regexp.Regexp

RouteRegex returns a regex pattern for the route. The regex is compiled once and cached for performance.

func (*Route) String

func (r *Route) String() string

String returns a string representation of the route.

type RouteGroup

type RouteGroup struct {
	// Prefix is the URL prefix for all routes in the group
	Prefix string
	// Middleware is applied to all routes in the group
	Middleware []Middleware
	// Routes are the routes in this group
	Routes []*ManualRoute
	// Groups are nested route groups
	Groups []*RouteGroup
	// Parent is the parent group (nil for root)
	Parent *RouteGroup
	// Meta contains group metadata
	Meta map[string]interface{}
	// contains filtered or unexported fields
}

RouteGroup represents a group of routes with shared configuration.

func (*RouteGroup) DELETE

func (g *RouteGroup) DELETE(path string, handler Handler, middleware ...Middleware) *ManualRoute

DELETE registers a DELETE route in the group.

func (*RouteGroup) GET

func (g *RouteGroup) GET(path string, handler Handler, middleware ...Middleware) *ManualRoute

GET registers a GET route in the group.

func (*RouteGroup) Group

func (g *RouteGroup) Group(prefix string, middleware ...Middleware) *RouteGroup

Group creates a nested route group.

func (*RouteGroup) PATCH

func (g *RouteGroup) PATCH(path string, handler Handler, middleware ...Middleware) *ManualRoute

PATCH registers a PATCH route in the group.

func (*RouteGroup) POST

func (g *RouteGroup) POST(path string, handler Handler, middleware ...Middleware) *ManualRoute

POST registers a POST route in the group.

func (*RouteGroup) PUT

func (g *RouteGroup) PUT(path string, handler Handler, middleware ...Middleware) *ManualRoute

PUT registers a PUT route in the group.

func (*RouteGroup) Page

func (g *RouteGroup) Page(path string, component templ.Component, middleware ...Middleware) *ManualRoute

Page registers a Templ component as a page in the group.

func (*RouteGroup) RegisterRoute

func (g *RouteGroup) RegisterRoute(method, path string, handler Handler, middleware ...Middleware) *ManualRoute

RegisterRoute registers a route in the group.

func (*RouteGroup) Use

func (g *RouteGroup) Use(middleware ...Middleware)

Use adds middleware to the group.

type RouteMatch

type RouteMatch struct {
	// Route is the matched route
	Route *Route
	// PathParams are the path parameters
	PathParams Params
	// QueryParams are the query parameters
	QueryParams *QueryParams
	// URL is the full URL
	URL *url.URL
}

RouteMatch represents a matched route with parameters.

func NewRouteMatch

func NewRouteMatch(route *Route, path string) (*RouteMatch, error)

NewRouteMatch creates a new route match.

func (*RouteMatch) Param

func (rm *RouteMatch) Param(key string) string

Param returns a path parameter value.

func (*RouteMatch) Query

func (rm *RouteMatch) Query(key string) string

Query returns a query parameter value.

type RouteOptions

type RouteOptions struct {
	Strategy RenderStrategy

	// ISR: duration after which the cached page is considered stale.
	// On a stale request the old page is served immediately and a background
	// goroutine re-renders and updates the cache (stale-while-revalidate).
	// Zero means "always revalidate" which behaves identically to SSR.
	RevalidateAfter time.Duration

	// PPR: names of dynamic slots that are excluded from the cached static shell
	// and re-rendered per-request. Each name must match a slot registered with
	// RegisterSlot for this page path.
	DynamicSlots []string
}

RouteOptions holds page-level options like rendering strategy.

func GetRouteOptions

func GetRouteOptions(path string) RouteOptions

GetRouteOptions returns route options from the global registry.

type RouteType

type RouteType int

RouteType represents the type of route.

const (
	RouteTypePage RouteType = iota
	RouteTypeLayout
	RouteTypeError
	RouteTypeAPI
)

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router manages all routes.

func NewRouter

func NewRouter(routesSource interface{}) *Router

NewRouter creates a new router with the given routes directory or filesystem. You can pass a string (directory path) or fs.FS.

func (*Router) GetErrorRoute

func (r *Router) GetErrorRoute(path string) *Route

GetErrorRoute returns the nearest error route for a given path.

func (*Router) GetLayouts

func (r *Router) GetLayouts() []*Route

GetLayouts returns all layout routes.

func (*Router) GetPages

func (r *Router) GetPages() []*Route

GetPages returns all page routes.

func (*Router) GetRoutes

func (r *Router) GetRoutes() []*Route

GetRoutes returns all routes.

func (*Router) Match

func (r *Router) Match(urlPath string) (*Route, map[string]string)

Match matches a URL path to a route.

func (*Router) MatchWithLayout

func (r *Router) MatchWithLayout(urlPath string) (*Route, []*Route, map[string]string)

MatchWithLayout matches a URL path and returns both the route and its layout chain.

func (*Router) ResolveLayoutChain

func (r *Router) ResolveLayoutChain(route *Route) []*Route

ResolveLayoutChain resolves the complete layout chain for a matched route. It returns all layouts from root to the nearest parent, ordered root-first.

func (*Router) Scan

func (r *Router) Scan() error

Scan scans the routes directory and builds the route tree.

type SlotFunc added in v0.1.4

type SlotFunc func(props map[string]interface{}) templ.Component

SlotFunc returns a templ.Component for a named PPR dynamic slot.

func GetSlot added in v0.1.4

func GetSlot(pagePath, slotName string) SlotFunc

GetSlot returns a PPR slot from the global registry.

Directories

Path Synopsis
Package generator provides code generation for automatic route registration.
Package generator provides code generation for automatic route registration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL