router

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ActiveRoute = "ACTIVE_ROUTE"

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerFunc

type HandlerFunc func(...interface{}) vecty.ComponentOrHTML

type Router

type Router struct {
	vecty.Core

	NotFound HandlerFunc
	// contains filtered or unexported fields
}

Router is a component which simplifies registering of components and proxying them depending on the path. This uses pushstate for navigation.

func NewRouter

func NewRouter() *Router

NewRouter returns new Router instance.

func (*Router) BeforeRendering

func (r *Router) BeforeRendering() func()

func (*Router) Handle

func (r *Router) Handle(pattern string, h HandlerFunc)

Handle register the handler for the matched pattern. At the moment a map is used to store the pattern/handler so matching is done on a full string comparison, the pattern is used as key.

TODO: use trie for pattern matching.

func (*Router) Mount

func (r *Router) Mount()

Mount registers event listener for onpopstate global event.

func (*Router) PushState

func (r *Router) PushState(path string, ctx ...interface{})

PushState re renders component registered on path.

func (*Router) Render

func (r *Router) Render() vecty.ComponentOrHTML

Render renders the active component register in the router. If there was any context supplied which calling pushState, it is passed to the handler.

func (*Router) Unmount

func (r *Router) Unmount()

Unmount stops listening for onpopstate events when the component is unmounted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL