can-route
Advanced tools
Comparing version 0.1.3 to 0.2.0
{ | ||
"name": "can-route", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "A simple regexp router that runs inside a `http.createServer` handler and returns false when it can’t route a request.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -61,3 +61,4 @@ # can-route | ||
window.onpopstate = function() { | ||
if (!can.route(window.location)) { | ||
var path = window.location || '/path/to/page' | ||
if (!can.route(path)) { | ||
// Handle 404 | ||
@@ -64,0 +65,0 @@ } |
@@ -25,3 +25,6 @@ var named = require('named-regexp').named | ||
Can.prototype.route = function(req, res) { | ||
var href = req.url || req.href | ||
var pathname = (typeof req == 'string' ? | ||
req : null | ||
) | ||
var method = (server ? | ||
@@ -32,13 +35,16 @@ req.method.toLowerCase() : 'get' | ||
var hash = !server && res === true | ||
var pathname = null | ||
if (server) { | ||
pathname = url.parse(href).pathname | ||
if (!pathname) { | ||
var href = req.url || req.href | ||
if (server) { | ||
pathname = url.parse(href).pathname | ||
} | ||
else { | ||
pathname = (hash ? | ||
href.substr(href.indexOf(req.pathname)) : | ||
req.pathname | ||
) | ||
} | ||
} | ||
else { | ||
pathname = (hash ? | ||
href.substr(href.indexOf(req.pathname)) : | ||
req.pathname | ||
) | ||
} | ||
var routes = this.routes | ||
@@ -45,0 +51,0 @@ var routeable = false |
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
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
8888
239
77