All Projects → marwan-at-work → Vecty Router

marwan-at-work / Vecty Router

Licence: apache-2.0
A declarative client-side router for Vecty applications.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Vecty Router

Rapid.js
An ORM-like Interface and a Router For Your API Requests
Stars: ✭ 700 (+2816.67%)
Mutual labels:  router
Preact Router
🌎 URL router for Preact.
Stars: ✭ 771 (+3112.5%)
Mutual labels:  router
Multiprocessrouter
一个多进程路由框架,使用APT处理路由接口的注册和初始化。多个模块间可以进行IPC调用。
Stars: ✭ 18 (-25%)
Mutual labels:  router
Found
Extensible route-based routing for React applications
Stars: ✭ 718 (+2891.67%)
Mutual labels:  router
Path To Regexp
Turn a path string such as `/user/:name` into a regular expression
Stars: ✭ 6,789 (+28187.5%)
Mutual labels:  router
Find My Way
A crazy fast HTTP router
Stars: ✭ 776 (+3133.33%)
Mutual labels:  router
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+2487.5%)
Mutual labels:  router
Storeon Async Router
Asynchronous router for Storeon. It provides possibility for prefetch the data, lazy load, navigation cancellation, and routes modification on the fly.
Stars: ✭ 22 (-8.33%)
Mutual labels:  router
Goplayspace
Advanced Go Playground frontend written in Go, with syntax highlighting, turtle graphics mode, and more
Stars: ✭ 765 (+3087.5%)
Mutual labels:  gopherjs
Macaw
🐦 Simple PHP router
Stars: ✭ 888 (+3600%)
Mutual labels:  router
Androuter
A android router framework used to map url to activities or actions.
Stars: ✭ 730 (+2941.67%)
Mutual labels:  router
Lion
Lion is a fast HTTP router for building modern scalable modular REST APIs in Go
Stars: ✭ 750 (+3025%)
Mutual labels:  router
One
一个极简高性能php框架,支持[swoole | php-fpm ]环境
Stars: ✭ 789 (+3187.5%)
Mutual labels:  router
Flutter thrio
flutter_thrio makes it easy and fast to add flutter to existing mobile applications, and provide a simple and consistent navigator APIs.
Stars: ✭ 717 (+2887.5%)
Mutual labels:  router
Kua
⚡️ Lightning fast URL routing in Python (trie router)
Stars: ✭ 18 (-25%)
Mutual labels:  router
Navaid
A navigation aid (aka, router) for the browser in 850 bytes~!
Stars: ✭ 648 (+2600%)
Mutual labels:  router
React Keeper
A routing library of React.
Stars: ✭ 774 (+3125%)
Mutual labels:  router
Realtime Android
数据驱动视图开发在 Android 平台的实现
Stars: ✭ 23 (-4.17%)
Mutual labels:  router
Koa Dec Router
An ES6 decorator + class based router, support inherit, override, priority, auto load controllers, etc.
Stars: ✭ 19 (-20.83%)
Mutual labels:  router
Xunlei Fastdick
迅雷快鸟 Xunlei Network Accelerator For Router
Stars: ✭ 789 (+3187.5%)
Mutual labels:  router

Vecty Router

A declarative client-side router for Vecty applications. Similar to react-router v4

Installation

go get marwan.io/vecty-router

Usage

You don't need to declare your routes at the top level. You can declare them inside any component and if they match they will render, otherwise, router will render an empty div instead.

package components

import (
	"github.com/hexops/vecty"
	"github.com/hexops/vecty/elem"
	"marwan.io/vecty-router"
)

// Body renders the <body> tag
type Body struct {
	vecty.Core
}

// Render renders the <body> tag with the App as its children
func (b *Body) Render() vecty.ComponentOrHTML {
	return elem.Body(
		router.NewRoute("/", &MainView{}, router.NewRouteOpts{ExactMatch: true}),
		router.NewRoute("/blog", &Blog{}, router.NewRouteOpts{}),
		router.NewRoute("/blog/{id}", &PostView{}, router.NewRouteOpts{ExactMatch: true}),
	)
}

To retrieve a named variable like {id} in the example above you can do

// Render returns every title
func (pv *PostView) Render() vecty.ComponentOrHTML {
	id := router.GetNamedVar(pv)["id"]
	return elem.Div(
		vecty.Text(id),
	)
}

Other features

Navigation through links
func (c *component) Render() vecty.ComponentOrHTML {
	return elem.Span(
		router.Link("/my/route", "click here", router.LinkOptions{}),
	)
}
Programatically navigate to a route
router.Redirect("/my/route")

Status

Currently vecty-router does not fallback to hash routing if the History API is not on your browser. It also calls vecty.Rerender on all routes whenever a route changes. It should/will do its own deducing of whether to call rerender on a route or not based on route matches and whether it's already mounted or not.

Alternatives

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].