From 1fa946110a0af5abaf1f51f918652126241a9eb0 Mon Sep 17 00:00:00 2001 From: Brian Suh Date: Sat, 4 Oct 2014 12:17:48 -0700 Subject: [PATCH 1/2] create test for #290 --- tests/mithril-tests.js | 14 ++++++++++++-- tests/mock.js | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 1d379977..00e17dd7 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -861,10 +861,20 @@ function testMithril(mock) { var root = mock.document.createElement("div") m.route.mode = "pathname" m.route(root, "/test2", { - "/test2": {controller: function() {}, view: function() {return "foo"}} + "/test2": { + controller: function() {}, + view: function() { + return [ + "foo", + m("a", { href: "/test2", config: m.route }, "Test2") + ] + } + } }) mock.requestAnimationFrame.$resolve() //teardown - return mock.location.pathname == "/test2" && root.childNodes[0].nodeValue === "foo" + return mock.location.pathname == "/test2" && + root.childNodes[0].nodeValue === "foo" && + root.childNodes[1].href == "/test2" }) test(function() { mock.requestAnimationFrame.$resolve() //setup diff --git a/tests/mock.js b/tests/mock.js index beea4423..10999206 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -38,7 +38,9 @@ mock.window = new function() { }, getAttribute: function(name, value) { return this[name] - } + }, + addEventListener: function () {}, + removeEventListener: function () {} } } window.document.createElementNS = function(namespace, tag) { From 8d2434ac21b36552f45ffb78fc599efcb40e7e6c Mon Sep 17 00:00:00 2001 From: Brian Suh Date: Sat, 4 Oct 2014 11:59:39 -0700 Subject: [PATCH 2/2] #290 fix m.route hrefs for pathname mode --- mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 50479b0d..1949e13e 100644 --- a/mithril.js +++ b/mithril.js @@ -548,7 +548,7 @@ Mithril = m = new function app(window, undefined) { var context = arguments[2] if (!isInitialized) { context.href = element.getAttribute("href") - element.href = window.location.pathname + modes[m.route.mode] + context.href + element.href = (m.route.mode !== 'pathname' ? window.location.pathname : '') + modes[m.route.mode] + context.href element.removeEventListener("click", routeUnobtrusive) element.addEventListener("click", routeUnobtrusive) }