router

package
v0.0.0-...-e4b31ca Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 8 Imported by: 1

README

Gas-router - web router for gas framework

Dependencies:
  1. gas
  2. gascore/dom (fork from dennwc/dom) - DOM bindings

Documentation

Index

Constants

View Source
const ChangeRouteEvent = "changeroute"

ChangeRouteEvent name for custom event

Variables

This section is empty.

Functions

func SupportHistory

func SupportHistory() bool

SupportHistory return ture if browser support "HTML5 History API"

Types

type Change

type Change func(path string, replace bool)

type ChangeDynamic

type ChangeDynamic func(name string, params, queries gas.Map, replace bool)

type Ctx

type Ctx struct {
	Routes   []Route
	Settings Settings
	This     *routerComponent

	Before, After func(to, from *RouteInfo) error
	// contains filtered or unexported fields
}

Ctx router context

func (*Ctx) ChangeRoute

func (ctx *Ctx) ChangeRoute(path string, replace bool)

ChangeRoute change current route

func (*Ctx) ChangeRouteDynamic

func (ctx *Ctx) ChangeRouteDynamic(name string, params, queries gas.Map, replace bool)

ChangeRouteDynamic change current route with params and queries

func (*Ctx) CustomPush

func (ctx *Ctx) CustomPush(path string, replace bool)

func (*Ctx) CustomPushDynamic

func (ctx *Ctx) CustomPushDynamic(name string, params, queries gas.Map, replace bool)

func (*Ctx) GetRouter

func (ctx *Ctx) GetRouter() *gas.C

GetRouter return gas router element

func (*Ctx) Init

func (ctx *Ctx) Init()

Init initialize router ctx

func (ctx *Ctx) Link(to string, e gas.External) *gas.Element

Link create link to route

func (*Ctx) LinkWithParams

func (ctx *Ctx) LinkWithParams(name string, params, queries gas.Map, e gas.External) *gas.Element

LinkWithParams create link to route with queries and params

func (*Ctx) Push

func (ctx *Ctx) Push(path string)

Push push user to another page

func (*Ctx) PushDynamic

func (ctx *Ctx) PushDynamic(name string, params, queries gas.Map)

PushDynamic push user to another route with params and queries

func (*Ctx) Replace

func (ctx *Ctx) Replace(path string)

Replace replace current page

func (*Ctx) ReplaceDynamic

func (ctx *Ctx) ReplaceDynamic(name string, params, queries gas.Map)

ReplaceDynamic replace current page with page generated from name, params and queries

type Middleware

type Middleware func(info *MiddlewareInfo) (stop bool, err error)

type MiddlewareInfo

type MiddlewareInfo struct {
	To, From *RouteInfo

	Change        Change
	ChangeDynamic ChangeDynamic
}

type Route

type Route struct {
	Name string
	Path string

	Component func(info *RouteInfo) *gas.Component

	Exact     bool
	Sensitive bool

	Redirect string

	RedirectName    string  // redirecting to route name
	RedirectParams  gas.Map // pararms for rederecting to route
	RedirectQueries gas.Map // queries for rederecting to route

	Before, After Middleware

	Childes []Route
}

Route information about route

type RouteInfo

type RouteInfo struct {
	Name string
	URL  string

	Params      gas.Map // /links/:foo => {"foo": "bar"}
	QueryParams gas.Map // /links?foo=bar => {"foo": "bar"}

	Route Route

	Ctx *Ctx
}

RouteInfo info about current route for router

type Settings

type Settings struct {
	BaseName string

	HashMode   bool
	HashSuffix string // "!", "/" for "#!", "#/"

	GetUserConfirmation func() bool
	ForceRefresh        bool

	NotFound func() *gas.Component

	MaxRouteParams int
}

Settings router settings

Jump to

Keyboard shortcuts

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