All Projects → jamesplease → backbone.base-router

jamesplease / backbone.base-router

Licence: MIT License
A better starting point for building a new Backbone Router.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to backbone.base-router

yarr
A React router library enabling the render-as-you-fetch concurrent UI pattern.
Stars: ✭ 97 (+97.96%)
Mutual labels:  router
whip
Simple fast http server for nim based on httpbeast and nest for high performance routing
Stars: ✭ 55 (+12.24%)
Mutual labels:  router
trail
Routing library for the Scala platform
Stars: ✭ 76 (+55.1%)
Mutual labels:  router
radvd
radvd | Official repository: https://github.com/radvd-project/radvd
Stars: ✭ 138 (+181.63%)
Mutual labels:  router
chomex
Chrome Extension Messaging Routing Kit / Promisify Chrome Messaging / LocalStorage Object Mapper
Stars: ✭ 41 (-16.33%)
Mutual labels:  router
TutoAsus
Tutorial on how to setup a nginx reverse proxy on Asus router with Merlin firmware, and get Let's Encrypt certificate with acme.sh.
Stars: ✭ 35 (-28.57%)
Mutual labels:  router
smoovy
A collection of small and useful js packages (smooth scrolling, utils, etc.) preventing copy & paste
Stars: ✭ 25 (-48.98%)
Mutual labels:  router
TG799VAC-XTREME-17.2-MINT
My personal unique wiki for hacking the router firmware used by (Telia)TG799vac Xtream v17.2-MINT delivered from Technicolor
Stars: ✭ 71 (+44.9%)
Mutual labels:  router
universal-router
↩️ Router for every occasions
Stars: ✭ 64 (+30.61%)
Mutual labels:  router
VueStudy
Vue.js学习系列示例代码及教程
Stars: ✭ 80 (+63.27%)
Mutual labels:  router
react-native-boilerplate
Ready-made structure of your next React Native application within a few minutes.
Stars: ✭ 36 (-26.53%)
Mutual labels:  router
highway
Highway - A Modern Javascript Transitions Manager
Stars: ✭ 1,349 (+2653.06%)
Mutual labels:  router
froute
Type safe and flexible router for React
Stars: ✭ 31 (-36.73%)
Mutual labels:  router
espresso.js
Super minimal MVC library
Stars: ✭ 521 (+963.27%)
Mutual labels:  backbone
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-71.43%)
Mutual labels:  router
yew-router
Router extension to yew
Stars: ✭ 27 (-44.9%)
Mutual labels:  router
nuxt-interpolation
Nuxt.js module as directive for binding every link to catch the click event, and if it's a relative link router will push.
Stars: ✭ 38 (-22.45%)
Mutual labels:  router
flexible-yolov5
More readable and flexible yolov5 with more backbone(resnet, shufflenet, moblienet, efficientnet, hrnet, swin-transformer) and (cbam,dcn and so on), and tensorrt
Stars: ✭ 282 (+475.51%)
Mutual labels:  backbone
ROS Scripts
Scripts for RouterOS (MikroTik devices)
Stars: ✭ 81 (+65.31%)
Mutual labels:  router
dodgr
Distances on Directed Graphs in R
Stars: ✭ 106 (+116.33%)
Mutual labels:  router

backbone.base-router

A better starting point for creating your own routing abstractions in Backbone.

What problems does this library solve?

Backbone's Router has two frustrating properties: it is too simple and too difficult to change. This library solves the second problem to make it easier for you to solve the first problem.

Instead of requiring that you associate a callback with a route, this library lets you associate whatever you'd like with a route. It can be a callback if you want, but it can also be an object, or even a string.

Whenever a Route is matched, a single method on the Router is called. This method is passed a single argument, routeData, that contains as much about the matched route as possible. Included this object are parsed query parameters, named fragment params, and the object you associated with the route, among other things. This single point-of-entry, combined with all of this data, makes it remarkably easy to add new abstractions to the Router.

What problems doesn't this library solve?

This library is not an effort to rewrite Backbone.history. As such, some of History's quirks are carried over, too. For instance, the order that you specify your callbacks in still matters, as this is how Backbone.History matches routes.

Getting Started

The Single Point of Entry

The API for the Base Router is simple: there's a single callback that gets called when a Route is navigated to. This callback is a plethora of information you might need, such as parsed query parameters and whatever object was associated with the callback. This is the location where you build your abstractions from.

Removed features

Backbone.BaseRouter does more for you by doing less. The following features were removed from the router.

  • A callback, if specified, is not automatically executed
  • No routing-related events are fired

The point of removing these features is that it gives you complete control over the Routing mechanism. It's simple to add them back in. Or you can change them to be exactly how you want. Or just leave them out. It's entirely up to you.

Example Usage

See the examples/ directory. There are READMEs for each example.

API

onNavigate( routeData )

The single point of entry is the onNavigate method. This method is called each time the user navigates via Backbone.history.

// Create a new Base Router
var router = new BaseRouter();

// Each time the user navigates to a matched route, a console message
// logs all of the data passed to the callback.
router.onNavigate = function(routeData) {
  console.log('The user has navigated!', routeData);
};

In addition to being called everytime that the user navigates to a matched route, which in itself is useful, the callback is passed a plethora of useful data related to the navigation action. This information is contained in the routeData argument.

routeData

linked

The object that was associated with this route. In a traditional Backbone router, this is always a callback that is executed. In the BaseRouter, this can be anything, and no assumptions are made about what you should do with it.

route

The regular expression that matched the URI fragment.

originalRoute

If the route was registered as a string, and not a regular expression, then this will be that original string. Otherwise, it is undefined.

params

An object which has keys that are the named parameters from the Route, and corresponding values from the URL.

query

An object representation of the query string in the URI fragment.

queryString

The original query string in the URI fragment. undefined if no query string given

router

The router instance that this route was registered on.

uriFragment

The URI fragment that was matched.

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].