Documentation
¶
Overview ¶
Package router maps URL paths to screens. With folder routing, a project's pages/ directory is the map: each folder holding a page.go is a route, and a folder named _name is a parameter.
pages/page.go / pages/orders/page.go /orders pages/orders/_id/page.go /orders/:id
`nimbus native gen` (run by every build) turns the folders into a static table, pages/routes_gen.go, so matching costs a few string compares and no reflection. Each page.go declares a Page component; parameters land in fields tagged param:
package order // pages/orders/_id
type Page struct {
ID int `param:"id"`
}
func (p Page) Title() string { return fmt.Sprintf("Order #%d", p.ID) } // optional
func (p Page) Render(c *ui.Ctx) ui.Component { ... }
Register the table once, then navigate by path from any screen:
router.Register(pages.Routes) router.Push(c, "/orders/42")
Index ¶
Constants ¶
This section is empty.
Variables ¶
NavigatorKey is the ui.SessionValue key of a session's Navigator.
Functions ¶
func Link ¶
Link is a pressable that goes to path: router.Push when tapped, and on the web a real link that crawlers and new tabs follow.
router.Link("/orders/42", ui.Style{}, ui.Text("Order #42", ui.Style{}))
func Patterns ¶
func Patterns() []string
Patterns lists the routes' patterns, most specific first: the web host builds its sitemap from the ones without parameters.
func Push ¶
Push shows the page at path on top of the Stack the component is in, titled by its Title method or else its last static path segment. Outside a Stack, on the web, it goes to that page and its URL. It reports false, and changes nothing, when no route matches.
Types ¶
type Head ¶
type Head struct {
Title string
Description string
Image string // absolute URL of a preview image (og:image)
NoIndex bool // keep the page out of search results
}
Head is what a page tells search engines and link previews: the web host puts it in the page's <head>. Pages provide it with a method:
func (p Page) Head() router.Head {
return router.Head{Title: "Order #42", Description: "…"}
}
type Navigator ¶
Navigator moves between pages where there is no Stack: the web host implements it to change the page and the browser's URL. A session puts it in its values under NavigatorKey.
type Params ¶
Params are a matched path's parameters by name.
func Match ¶
Match finds the page for a path ("/orders/42?tab=items"): its component and parameters, with query values added. false when no route matches.