Merge pull request #301 from bsuh/issue-290

Issue #290
This commit is contained in:
Leo Horie 2014-10-04 21:39:08 -04:00
commit 50a4b6fd01
3 changed files with 16 additions and 4 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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) {