Giorouter is package meant to simplify routing in a Gioui app.
It provides a simple API to use:
Push(route string)Pop()CanPop() bool`
typeHomestruct {
Router*giorouter.Routerclick*widget.Clickable
}
func (h*Home) Layout(gtx layout.Context, th*material.Theme) {
ifh.click.Clicked() {
h.Router.Push("about")
}
// Draw your page...
}
typeAboutstruct {
Router*giorouter.Router
}
func (a*About) Layout(gtx layout.Context, th*material.Theme) {
ifa.click.Clicked() {
a.Router.Pop()
}
// Draw your page...
}
funcmain() {
th:=material.NewTheme(gofont.Collection())
router:=giorouter.NewRouter(th)
home:=Home{Router: router}
about:=About{Router: router}
router.SetRoutes(giorouter.Routes{
"home": &home,
"about": &about,
}, "home")
gofunc() {
w:=app.NewWindow()
varops op.Opsfor {
select {
casee:=<-w.Events():
switche:=e.(type) {
case system.FrameEvent:
gtx:=layout.NewContext(&ops, e)
router.Layout(gtx) // Draw the current pagee.Frame(gtx.Ops)
case system.DestroyEvent:
os.Exit(0)
}
case<-router.C:
// Redraw the screen when the route is changingw.Invalidate()
}
}
}()
app.Main()
}