跳到正文

Router

将 QuickGUI 核心路由投影到 QuickGUI UI,支持嵌套布局和容量受限的内存历史。

正在加载交互演示…

#导入

从 github.com/egoist/quickgui/go/ui 导入 ui。

import (
	"github.com/egoist/quickgui/go/ui"
)

#用法

func RouterExample() *native.Node {
	return ui.Router(ui.RouterProps{
		InitialPath: "/",
		Routes: []*ui.RouteDeclaration{
			ui.Route(
				"/",
				func() *native.Node {
					return ui.Link(
						ui.LinkProps{Href: "/settings"},
						"Settings",
					)
				},
			),
			ui.Route(
				"/settings",
				func() *ui.Element { return ui.Text("Settings") },
			),
		},
		Fallback: func() *ui.Element { return ui.Text("Page not found") },
	})
}

#结构

  • ui.Router
  • ui.Route
  • ui.Layout
  • ui.Link
  • ui.Outlet

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

ui.Router(props RouterProps) *native.Node

Router renders the route table's matched chain. Declarations never change after creation.

Routes[]*RouteDeclaration—

Static route declarations built with `ui.Route` and `ui.Layout`.

[]*RouteDeclaration
查看源码
InitialPathstring—

Initial destination for the bounded in-memory history.

string
查看源码
FallbackComponent—

Content rendered when no route matches.

Component
查看源码