Documentation ¶
Index ¶
- type BindParam
- type ErrMissingPrefix
- type EventEnv
- type Navigator
- type NavigatorOpt
- type NavigatorRef
- type NavigatorSetter
- type RouteHandler
- type RouteHandlerFunc
- type RouteMatch
- type Router
- func (r *Router) AddRoute(path string, rh RouteHandler) error
- func (r *Router) AddRouteExact(path string, rh RouteHandler) error
- func (r *Router) BrowserAvail() bool
- func (r *Router) GetNotFound() RouteHandler
- func (r *Router) ListenForPopState() error
- func (r *Router) MustAddRoute(path string, rh RouteHandler)
- func (r *Router) MustAddRouteExact(path string, rh RouteHandler)
- func (r *Router) MustNavigate(path string, query url.Values, opts ...NavigatorOpt)
- func (r *Router) Navigate(path string, query url.Values, opts ...NavigatorOpt) error
- func (r *Router) ProcessRequest(req *http.Request)
- func (r *Router) Pull() error
- func (r *Router) Push(opts ...NavigatorOpt) error
- func (r *Router) SetNotFound(rh RouteHandler)
- func (r *Router) SetPathPrefix(pfx string)
- func (r *Router) SetUseFragment(v bool)
- func (r *Router) UnbindParams()
- func (r *Router) UnlistenForPopState() error
- type StringParam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrMissingPrefix ¶
type ErrMissingPrefix struct { Message string // error message Path string // path which is missing the prefix }
ErrMissingPrefix is returned when a prefix was expected but not found.
type EventEnv ¶
type EventEnv interface { Lock() // acquire write lock UnlockOnly() // release write lock UnlockRender() // release write lock and request re-render }
EventEnv is our view of a Vugu EventEnv
type Navigator ¶
type Navigator interface { string, query url.Values, opts ...NavigatorOpt) Navigate(path string, query url.Values, opts ...NavigatorOpt) error // Only works in wasm environment otherwise has no effect. Push(opts ...NavigatorOpt) error }MustNavigate(path
Navigator interface has the methods commonly needed throughout the application to go to different pages and deal with routing.
type NavigatorOpt ¶
type NavigatorOpt interface {
}NavigatorOpt is a marker interface to ensure that options to Navigator are passed intentionally.
var ( // current history entry rather than pushing to the stack. // Implemented using window.history.replaceState() NavReplace NavigatorOpt = intNavigatorOpt(1) // the current component state. It can be used when a component // has already accounted for the render in some other way and // just wants to inform the Navigator of the current logical path and query. NavSkipRender NavigatorOpt = intNavigatorOpt(2) )
type NavigatorRef ¶
type NavigatorRef struct {
}NavigatorRef embeds a reference to a Navigator and provides a NavigatorSet method.
func (*NavigatorRef) NavigatorSet ¶
func (nr *NavigatorRef) NavigatorSet(v Navigator)
NavigatorSet implements NavigatorSetter interface.
type NavigatorSetter ¶
type NavigatorSetter interface {
}NavigatorSetter is implemented by things that can accept a Navigator.
type RouteHandler ¶
type RouteHandler interface {
RouteHandle(rm *RouteMatch)
}
RouteHandler implementations are called in response to a route matching (being navigated to).
type RouteHandlerFunc ¶
type RouteHandlerFunc func(rm *RouteMatch)
RouteHandlerFunc implements RouteHandler as a function.
func (RouteHandlerFunc) RouteHandle ¶
func (f RouteHandlerFunc) RouteHandle(rm *RouteMatch)
RouteHandle implements the RouteHandler interface.
type RouteMatch ¶
type RouteMatch struct { Path string // path input (with any params interpolated) RoutePath string // route path pattern with params as :param Params url.Values // parameters (combined query and route params) Exact bool // true if the path is an exact match or false if just the prefix Request *http.Request // if ProcessRequest is used, this will be set to Request instance passed to it; server-side only // contains filtered or unexported fields }
RouteMatch describes a request to navigate to a route.
func (*RouteMatch) Bind ¶
func (r *RouteMatch) Bind(name string, param BindParam)
Bind adds a BindParam to the list of bound parameters. Later calls to Bind with the same name will replace the bind from earlier calls.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router handles URL routing.
func (*Router) AddRoute ¶
func (r *Router) AddRoute(path string, rh RouteHandler) error
AddRoute adds a route to the list.
func (*Router) AddRouteExact ¶
func (r *Router) AddRouteExact(path string, rh RouteHandler) error
AddRouteExact adds a route but only calls the handler if the path provided matches exactly. E.g. an exact route for "/a" will not fire when "/a/b" is navigated to (whereas AddRoute would do this).
func (*Router) BrowserAvail ¶
BrowserAvail returns true if in browser mode.
func (*Router) GetNotFound ¶
func (r *Router) GetNotFound() RouteHandler
GetNotFound returns what was set by SetNotFound. Provided to facilitate code that needs to wrap an existing not found behavior with another one.
func (*Router) ListenForPopState ¶
ListenForPopState registers an event listener so the user navigating with forward/back/history or fragment changes will be detected and handled by this router. Any call to SetUseFragment or SetPathPrefix should occur before calling ListenForPopState.
Only works in wasm environment and if called outside it will have no effect and return error.
func (*Router) MustAddRoute ¶
func (r *Router) MustAddRoute(path string, rh RouteHandler)
MustAddRoute is like AddRoute but panics upon error.
func (*Router) MustAddRouteExact ¶
func (r *Router) MustAddRouteExact(path string, rh RouteHandler)
MustAddRouteExact is like AddRouteExact but panic's upon error.
func (*Router) MustNavigate ¶
func (r *Router) MustNavigate(path string, query url.Values, opts ...NavigatorOpt)
MustNavigate is like Navigate but panics upon error.
func (*Router) ProcessRequest ¶
ProcessRequest processes the route contained in request. This is meant for server-side use with static rendering.
func (*Router) Pull ¶
Pull will read the current browser URL and navigate to it. This is generally called once at application startup. Only works in wasm environment otherwise has no effect and will return error. If a path prefix has been set and the path read does not start with prefix then an error of type *ErrMissingPrefix will be returned.
func (*Router) Push ¶
func (r *Router) Push(opts ...NavigatorOpt) error
Push will take any bound parameters and put them into the URL in the appropriate place. Only works in wasm environment otherwise has no effect.
func (*Router) SetNotFound ¶
func (r *Router) SetNotFound(rh RouteHandler)
SetNotFound assigns the handler for the case of no exact match reoute.
func (*Router) SetPathPrefix ¶
SetPathPrefix sets the path prefix to use prepend or stripe when iteracting with the browser or external requests. Internally paths do not use this prefix. For example, calling `r.SetPrefix("/pfx"); r.Navigate("/a", nil)` will result in /pfx/a in the browser, but the path will be treated as just /a during processing. The prefix is stripped from the URL when calling Pull() and also when http.Requests are processed server-side.
func (*Router) SetUseFragment ¶
SetUseFragment sets the fragment flag which if set means the fragment part of the URL (after the "#") is used as the path and query string. This can be useful for compatibility in applications which are served statically and do not have the ability to handle URL routing on the server side. This option is disabled by default. If used it should be set immediately after creation. Changing it after navigation may have undefined results.
func (*Router) UnbindParams ¶
func (r *Router) UnbindParams()
UnbindParams will remove any previous parameter bindings. Note that this is called implicitly when navigiation occurs since that involves re-binding newly based on the path being navigated to.
func (*Router) UnlistenForPopState ¶
UnlistenForPopState removes the listener created by ListenForPopState.
type StringParam ¶
type StringParam string
StringParam implements BindParam on a string.
func (*StringParam) BindParamRead ¶
func (s *StringParam) BindParamRead() []string
BindParamRead implements BindParam.
func (*StringParam) BindParamWrite ¶
func (s *StringParam) BindParamWrite(v []string)
BindParamWrite implements BindParam.