Gong provides a powerful and flexible routing system that supports both simple and nested routing patterns. This documentation covers the core routing concepts and how to implement them in your Gong applications.
Create a basic route using the gong.NewRoute() function:
gong.NewRoute("/", HomeComponent)
This renders the HomeComponent when the root path ("/") is accessed.
Define dynamic path parameters using the {name} syntax.
gong.NewRoute("/user/{name}", UserComponent)
Create hierarchical routes with the gong.RouteWithChildren(...Route) functional option:
gong.NewRoute("/home", HomeComponent,
gong.WithChildren(
gong.NewRoute("/users", UserListComponent),
),
)
In this example, the UserListComponent will be rendered inside the Outlet of the HomeComponent.
Use the Outlet component to define where child route components are rendered.
templ (c HomeComponent) View() {
HOME
@gong.Outlet()
}
Use the Link component for client-side navigation with partial page updates.
templ (c HomeComponent) View() {
@gong.Link("/users") {
Users
}
}