From eda32fef47682e29c297e3ce7af8533115be1783 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 10 Jul 2014 08:51:31 -0400 Subject: [PATCH] fix node insertion bug when using document as root --- docs/routing.md | 6 +++--- mithril.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/routing.md b/docs/routing.md index b2706130..887a423c 100644 --- a/docs/routing.md +++ b/docs/routing.md @@ -41,13 +41,13 @@ var dashboard = { } } +//setup routes to start w/ the `#` symbol +m.route.mode = "hash"; + //define a route m.route(document.body, "/dashboard/johndoe", { "/dashboard/:userID": dashboard }); - -//setup routes to start w/ the `#` symbol -m.route.mode = "hash"; ``` This redirects to the URL `http://server/#/dashboard/johndoe` and yields: diff --git a/mithril.js b/mithril.js index 0a9b2f8f..6053e545 100644 --- a/mithril.js +++ b/mithril.js @@ -287,9 +287,10 @@ Mithril = m = new function app(window) { if (html === undefined) html = window.document.createElement("html") if (node.nodeName == "HTML") html = node else html.appendChild(node) - if (window.document.documentElement !== html) { + if (window.document.documentElement && window.document.documentElement !== html) { window.document.replaceChild(html, window.document.documentElement) } + else window.document.appendChild(html) }, insertBefore: function(node) { this.appendChild(node)