From d7f6355d853e8db2a23adf7ebe749687ab32d487 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Fri, 14 Jul 2017 00:08:47 -0700 Subject: [PATCH] add setHash helper --- src/core/plugins/deep-linking/helpers.js | 7 +++++++ src/core/plugins/deep-linking/layout-wrap-actions.js | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/core/plugins/deep-linking/helpers.js diff --git a/src/core/plugins/deep-linking/helpers.js b/src/core/plugins/deep-linking/helpers.js new file mode 100644 index 00000000..d06bbe27 --- /dev/null +++ b/src/core/plugins/deep-linking/helpers.js @@ -0,0 +1,7 @@ +export const setHash = (value) => { + if(value) { + return history.pushState(null, null, `#${value}`) + } else { + return window.location.hash = "" + } +} diff --git a/src/core/plugins/deep-linking/layout-wrap-actions.js b/src/core/plugins/deep-linking/layout-wrap-actions.js index 39a2c8e8..ec7421c1 100644 --- a/src/core/plugins/deep-linking/layout-wrap-actions.js +++ b/src/core/plugins/deep-linking/layout-wrap-actions.js @@ -1,3 +1,5 @@ +import { setHash } from "./helpers" + export const show = (ori, system) => (...args) => { ori(...args) try { @@ -6,17 +8,17 @@ export const show = (ori, system) => (...args) => { if(type === "operations-tag" || type === "operations") { if(!shown) { - return window.location.hash = "" + return setHash("/") } if(type === "operations") { let [, operationId, tag] = thing - window.location.hash = `/${tag}/${operationId}` + setHash(`/${tag}/${operationId}`) } if(type === "operations-tag") { let [, tag] = thing - window.location.hash = `/${tag}` + setHash(`/${tag}`) } }