Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-router

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-router - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/events.js

31

index.js

@@ -15,3 +15,3 @@ module.exports = Router

if (routes) {
Object.keys(routes).forEach(function (key) {
Object.keys(routes).forEach(function BaseRouter_forEachRoutes (key) {
self.route(key, routes[key])

@@ -24,7 +24,7 @@ })

Router.prototype.route = function (name, model) {
Router.prototype.route = function BaseRouter_route (name, model) {
this._router.addRoute(name, model)
}
Router.prototype.transitionTo = function (name) {
Router.prototype.transitionTo = function BaseRouter_transitionTo (name, params) {
var self = this

@@ -52,3 +52,3 @@

// TODO: Detect queryParams
var data = model.fn(model.params, done)
var data = model.fn(params || model.params, done)
if (data) {

@@ -70,3 +70,3 @@ if (typeof data.then === 'function') {

// TODO: Still not sure about this API
Router.prototype.serve = function (fn) {
Router.prototype.serve = function BaseRouter_serve (fn) {
var self = this

@@ -86,3 +86,3 @@ return function (request, response) {

Router.prototype._initBrowser = function (which) {
Router.prototype._initBrowser = function BaseRouter_initBrowser (which) {
var self = this

@@ -99,17 +99,24 @@ var window = require('global/window')

// Used to prevent double calling pushState or hashchange
var preventOnTransition = false
if (usePush) {
window.onpopstate = function (e) {
window.onpopstate = function BaseRouter_onpopstate (e) {
preventOnTransition = true
self.transitionTo(location.pathname)
}
self.on('transition', function (page) {
window.history.pushState({}, page, page)
self.on('transition', function BaseRouter_popStateTransition (page) {
if (!preventOnTransition) window.history.pushState({}, page, page)
preventOnTransition = false
})
} else {
window.addEventListener('hashchange', function (e) {
window.addEventListener('hashchange', function BaseRouter_hashchange (e) {
preventOnTransition = true
self.transitionTo(location.hash.slice(1))
}, false)
self.on('transition', function (page) {
location.hash = '#' + page
self.on('transition', function BaseRouter_hashTransition (page) {
if (!preventOnTransition) location.hash = '#' + page
preventOnTransition = false
})
}
}
{
"name": "base-router",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple and portable router for the client and server.",
"main": "index.js",
"scripts": {
"test": "standard && node test.js && zuul --local 9966 -- test.js",
"ci": "standard && node test.js && zuul -- test.js",
"test": "standard && tape test/*.js && zuul --local 9966 -- test/*.js",
"ci": "standard && node test/*.js && zuul -- test/*.js",
"start": "budo example.js --live"

@@ -10,0 +10,0 @@ },

@@ -116,5 +116,13 @@ # base-router

### `router.transitionTo(name)`
```js
router.route('/user/:id', function (params, done) {
done(null, params.id)
})
```
### `router.transitionTo(name[, params])`
Transitions to the given route `name`.
Optionally you can supply `params` to override the params given to a route.
### `router.currentRoute`

@@ -121,0 +129,0 @@ The last resolved route we are currently on.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc