From 753944efe872df5339aa8dfd8d976fd57cda005b Mon Sep 17 00:00:00 2001 From: darda Date: Thu, 23 Jun 2016 08:49:18 +0200 Subject: [PATCH 1/4] Push route to history stack, when using parameters Bugfix for issue #1124 The condition has been changed, which is deciding to push the a route to history stack. I think, it is necessary to compare the old route with the current route, instead of old route with root (without parameters). --- mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 28030022..b9c9f123 100644 --- a/mithril.js +++ b/mithril.js @@ -1659,7 +1659,7 @@ var replaceHistory = (arguments.length === 3 ? arg2 : arg1) === true || - oldRoute === root + oldRoute === currentRoute if (global.history.pushState) { var method = replaceHistory ? "replaceState" : "pushState" From d327c92f0a93e2be3cdf5635479558a8d177bf46 Mon Sep 17 00:00:00 2001 From: Thomas Erfurth Date: Wed, 6 Jul 2016 10:54:46 +0200 Subject: [PATCH 2/4] Added tests for history modification when switching routes with parameters (#1125) --- test/mithril.route.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/mithril.route.js b/test/mithril.route.js index 76ac5c09..10b18762 100644 --- a/test/mithril.route.js +++ b/test/mithril.route.js @@ -836,6 +836,36 @@ describe("m.route()", function () { expect(mock.history.$$length).to.equal(0) }) + dit("modify history when redirecting to same route with different parameters", function(root) { + mode("search") + mock.history.$$length = 0 + + route(root, "/a", { + "/a": pure(function () { return "a" }), + "/b": pure(function () { return "b" }) + }) + + route("/b") + route("/b", { foo: "bar" }) + + expect(mock.history.$$length).to.equal(2) + }) + + dit("doesn't modify history when redirecting to same route with same parameters", function(root) { + mode("search") + mock.history.$$length = 0 + + route(root, "/a", { + "/a": pure(function () { return "a" }), + "/b": pure(function () { return "b" }) + }) + + route("/b", { foo: "bar" }) + route("/b", { foo: "bar" }) + + expect(mock.history.$$length).to.equal(1) + }) + context("m.route.strategy() === \"all\", identical views", function () { context("parent nodes", function () { dit("renders routes independently", function (root) { From c17ea5bbc83ff7eb752c92ad4e6e77e3d89a2ca0 Mon Sep 17 00:00:00 2001 From: darda Date: Thu, 23 Jun 2016 08:49:18 +0200 Subject: [PATCH 3/4] Push route to history stack, when using parameters Bugfix for issue #1124 The condition has been changed, which is deciding to push the a route to history stack. I think, it is necessary to compare the old route with the current route, instead of old route with root (without parameters). --- mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 4e972b89..7ec24ab1 100644 --- a/mithril.js +++ b/mithril.js @@ -1664,7 +1664,7 @@ var replaceHistory = (arguments.length === 3 ? arg2 : arg1) === true || - previousRoute === root + previousRoute === currentRoute if (global.history.pushState) { var method = replaceHistory ? "replaceState" : "pushState" From d6f7653e31a4320dded49c8bd7e32ee49a783a84 Mon Sep 17 00:00:00 2001 From: Thomas Erfurth Date: Wed, 6 Jul 2016 10:54:46 +0200 Subject: [PATCH 4/4] Added tests for history modification when switching routes with parameters (#1125) --- test/mithril.route.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/mithril.route.js b/test/mithril.route.js index 11c529a6..8653d0b4 100644 --- a/test/mithril.route.js +++ b/test/mithril.route.js @@ -838,6 +838,36 @@ describe("m.route()", function () { expect(mock.history.$$length).to.equal(0) }) + dit("modify history when redirecting to same route with different parameters", function(root) { + mode("search") + mock.history.$$length = 0 + + route(root, "/a", { + "/a": pure(function () { return "a" }), + "/b": pure(function () { return "b" }) + }) + + route("/b") + route("/b", { foo: "bar" }) + + expect(mock.history.$$length).to.equal(2) + }) + + dit("doesn't modify history when redirecting to same route with same parameters", function(root) { + mode("search") + mock.history.$$length = 0 + + route(root, "/a", { + "/a": pure(function () { return "a" }), + "/b": pure(function () { return "b" }) + }) + + route("/b", { foo: "bar" }) + route("/b", { foo: "bar" }) + + expect(mock.history.$$length).to.equal(1) + }) + context("m.route.strategy() === \"all\", identical views", function () { context("parent nodes", function () { dit("renders routes independently", function (root) {