diff --git a/package.json b/package.json index b96f2ac..102d2f8 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "@hyperapp/router", + "name": "hyperapp-patched-router", "description": "Declarative routing for Hyperapp using the History API.", "version": "0.7.0", "main": "dist/router.js", "module": "src/index.js", "license": "MIT", - "repository": "hyperapp/router", + "repository": "kidandcat/router", "files": [ "src", "dist" diff --git a/src/location.js b/src/location.js index 1bd704e..f940e92 100644 --- a/src/location.js +++ b/src/location.js @@ -2,6 +2,11 @@ function wrapHistory(keys) { return keys.reduce(function(next, key) { var fn = history[key] + // Do not wrap if it's already wrapped + if(history[key].toString().indexOf('CustomEvent("pushstate"') !== -1){ + return function(){}; + } + history[key] = function(data, title, url) { fn.call(this, data, title, url) dispatchEvent(new CustomEvent("pushstate", { detail: data })) @@ -41,6 +46,8 @@ export var location = { addEventListener("pushstate", handleLocationChange) addEventListener("popstate", handleLocationChange) + // Trigger actions.set + handleLocationChange({detail: null}); return function() { removeEventListener("pushstate", handleLocationChange)