grouter

package module
v0.0.0-...-b70b942 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2016 License: MIT Imports: 3 Imported by: 5

README

go-react-router

Build Status GoDoc

React-Router Bindings for GopherJS.

Will need https://github.com/bep/gr to run.

See it in action here: http://bego.io/goreact/examples/router/

See also:

Example Setup

var (
	component1   = gr.New(&clickCounter{title: "Counter 1", color: "#ff0066"})
	component2   = gr.New(&clickCounter{title: "Counter 2", color: "#339966"})
	component3   = gr.New(&clickCounter{title: "Counter 3", color: "#0099cc"})
	component3_2 = gr.New(&clickCounter{title: "Counter 3_2", color: "#ffcc66"})

	// WithRouter makes this.props.router happen.
	appComponent = gr.New(new(app), gr.Apply(grouter.WithRouter))

	router = grouter.New("/", appComponent).With(
		grouter.NewIndexRoute(grouter.Components{"main": component1}),
		grouter.NewRoute("c1", grouter.Components{"main": component1}),
		grouter.NewRoute("c2", grouter.Components{"main": component2}),
		grouter.NewRoute("c3", grouter.Components{"main": component3, "sub": component3_2}),
	)
)

Documentation

Overview

Package grouter implements GopherJS bindings for react-router.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsActive

func IsActive(props gr.Props, pathOrLoc string) bool

IsActive returns whether the path or location is active.

func Link(to, text string) gr.Modifier

Link creates a HTML anchor to the given path with the given text.

func MarkIfActive

func MarkIfActive(props gr.Props, pathOrLoc string) gr.Modifier

MarkIfActive marks by the active CSS class if the given path or location is active or not. If not active, a modifier that does nothing is returned.

func WithHistory

func WithHistory(history History) func(*Router) error

WithHistory is a configuration option to set the history implementation to use.

func WithRouter

func WithRouter(o *js.Object) *js.Object

WithRouter must be applied to the React component to get hold of the router object needed by MarkIfActive and friends.

Types

type Components

type Components map[string]gr.Component

Components represents named components for a route.

type History

type History struct {
	*js.Object
}

History for the Router.

type Route

type Route struct {
	// contains filtered or unexported fields
}

A Route is defined by a path and one or more components. Components can be named. Routes can be nested..

func NewIndexRoute

func NewIndexRoute(components Components) Route

NewIndexRoute defines the route used when the user visits "/". See https://github.com/reactjs/react-router/blob/master/docs/guides/IndexRoutes.md

func NewRoute

func NewRoute(path string, components Components, children ...Route) Route

NewRoute creates a new Route with the given path and named components and the supplied child routes.

type Router

type Router struct {
	*js.Object
	// contains filtered or unexported fields
}

Router represents a router.

func New

func New(path string, c gr.Component, options ...func(*Router) error) *Router

New creates a new Router with the given root path and component and options.

func (*Router) Node

func (r *Router) Node() *js.Object

Node creates a new React JS component of the Router defintion.

func (Router) With

func (r Router) With(routes ...Route) *Router

With creates a new Router with the provided children.

Directories

Path Synopsis
Package tests contains tests.
Package tests contains tests.

Jump to

Keyboard shortcuts

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