Page Link

Page Link component displays a link to another page of the app, opened with a page query. The page it opens reads the query as Params.Query.

It is a real link: it opens in a new tab on a middle click, and its url can be copied. It takes a page name and values, never a url, so it cannot point off the app. The url follows the app's page mode: /detail?group=a, or #/detail?group=a in hash mode and in the browser build. On the desktop it switches page the way the side nav does.

The text supports emoji shortcodes.

API

func PageLink(c *tgframe.Container, text, page string,
	query url.Values, conf ...*PageLinkConf)
  • c is Parent container.
  • text is the link text.
  • page is the name of the page to open. A page the app does not have fails the component: the run reports the error and the link is not drawn.
  • query is the page query. nil opens the page without one.
  • conf is an optional configuration, at most one.
// PageLinkConf is the configuration for the PageLink component.
type PageLinkConf struct {
	tgframe.Base // ID
}

Example

	// The query is untrusted: anything that is not a number is 0.
	n, err := strconv.Atoi(p.Query.Get("n"))
	if err != nil || n < 0 {
		n = 0
	}

	tgcomp.Text(p.Main, "n = "+strconv.Itoa(n))
	tgcomp.PageLink(p.Main, "Next", "page_link", url.Values{
		"n": {strconv.Itoa(n + 1)},
	})