How to do navigation in UI
suntong opened this issue · comments
suntong commented
I know there is a ctx.Navigate
, but how can I do app.Navigate("/thing")
when defining UI?
Quote from #412:
I call
app.Navigate("/thing")
Matt Crawford commented
ctx.Navigate is typically called from a user event like a button click
func (r *ComponentOne) Render() app.UI {
return app.Button().Text("go to two").OnClick(func(ctx app.Context, e app.Event) {
ctx.Navigate("/two")
})
}
suntong commented
Ah, yes!
Now, how to fix this app.Navigate
please?
func (c *city) OnNav(u *url.URL) {
key := u.Query().Get("city")
if key == "" {
key = "paris"
}
data, ok := cityStore[key]
if !ok {
// app.Navigate("/notfound")
return
}
c.data = data
c.Update()
}
Matt Crawford commented
V9 of OnNav is passed an app.Context. V6 was passed *url.URL.
// Navigator is the interface that describes a component that can perform
// additional actions when navigated on.
type Navigator interface {
Composer
// The function that called when the component is navigated on. It is always
// called on the UI goroutine.
OnNav(Context)
}
suntong commented
Ops, yes, thanks!