base-router
Advanced tools
Comparing version 1.0.1 to 1.0.2
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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16849
9
338
149
2