From 8a865d253f56942ee7aa6093bdc4494a1f28247b Mon Sep 17 00:00:00 2001 From: Scott Buchanan Date: Mon, 15 Jun 2020 10:48:19 -0400 Subject: [PATCH] fall back to full page load if new url doesn't have root element --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b314a0e..6bf5223 100644 --- a/index.js +++ b/index.js @@ -89,9 +89,13 @@ export default function app (selector, routes = ['*']) { .then(res => res.text()) .then(res => { const doc = new window.DOMParser().parseFromString(res, 'text/html') + + const newRoot = doc.querySelector(selector) + if (! newRoot) return window.location.href = href + const c = [ doc, - doc.querySelector(selector).innerHTML + newRoot.innerHTML ] cache.set(href, c) cb && cb(c[0], c[1], route)