diff --git a/src/deparam.js b/src/deparam.js index 45b41d1..80a6108 100644 --- a/src/deparam.js +++ b/src/deparam.js @@ -26,6 +26,7 @@ function toURLFragment(url) { if (root.lastIndexOf("/") === root.length - 1 && url.indexOf("/") === 0) { url = url.substr(1); } + return url; } @@ -49,7 +50,11 @@ function canRoute_getRule(url) { } function canRoute_deparam(url) { - + // Remove any trialing `/` to allow for pushstate to be deparamed properly + if (url.length > 1 && url.lastIndexOf("/") === url.length - 1) { + url = url.slice(0, -1); + } + var route = canRoute_getRule(url), querySeparator = bindingProxy.call("querySeparator"), paramsMatcher = bindingProxy.call("paramsMatcher"); diff --git a/test/param-deparam-test.js b/test/param-deparam-test.js index 08ad93b..0d6549d 100644 --- a/test/param-deparam-test.js +++ b/test/param-deparam-test.js @@ -326,6 +326,17 @@ QUnit.test("param / deparam / rule", function(assert) { input: { page: "foo", section: "bar" }, output: "foo/bar" }, + { + method: "deparam", + input: "foo/bar", + output: { page: "foo", section: "bar" } + }, + // handles trailing slash (`/`) in url + { + method: "deparam", + input: "foo/bar/", + output: { page: "foo", section: "bar" } + }, // handles falsey values // handles "" { @@ -336,7 +347,7 @@ QUnit.test("param / deparam / rule", function(assert) { { method: "deparam", input: "home/", - output: {} + output: { page: "home" } }, { method: "rule",