diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js index 48b7cb86bda46795bba8f2e582556afca006ab41..ae55adbce87c460a0b1e22a05e1396e6920d5bd7 100644 --- a/app/assets/javascripts/lib/utils/url_utility.js +++ b/app/assets/javascripts/lib/utils/url_utility.js @@ -256,12 +256,39 @@ export function removeParams(params, url = window.location.href, skipEncoding = return `${root}${writableQuery}${writableFragment}`; } +export function updateHistory({ state = {}, title = '', url, replace = false, win = window } = {}) { + if (win.history) { + if (replace) { + win.history.replaceState(state, title, url); + } else { + win.history.pushState(state, title, url); + } + } +} + /** * Returns value after the '#' in the location hash * @returns Current value of the hash, undefined if not set */ export const getLocationHash = () => window.location.hash?.split('#')[1]; +/** + * Sets location hash to the given value. + * When value is undefined, the hash is removed. + * @param {string} hash - use undefined to remove location hash + */ +export const setLocationHash = (hash) => { + if (hash === undefined) { + updateHistory({ + title: document.title, + url: window.location.pathname + window.location.search, + replace: true, + }); + } else { + window.location.hash = hash; + } +}; + /** * Returns a boolean indicating whether the URL hash contains the given string value * @param {string} hashName @@ -299,16 +326,6 @@ export const setUrlFragment = (url, fragment) => { return `${rootUrl}#${encodedFragment}`; }; -export function updateHistory({ state = {}, title = '', url, replace = false, win = window } = {}) { - if (win.history) { - if (replace) { - win.history.replaceState(state, title, url); - } else { - win.history.pushState(state, title, url); - } - } -} - export const escapeFileUrl = (fileUrl) => encodeURIComponent(fileUrl).replace(/%2F/g, '/'); export function webIDEUrl(route = undefined) { diff --git a/app/assets/javascripts/projects/new_v2/components/app.vue b/app/assets/javascripts/projects/new_v2/components/app.vue index a446c3cdcbb9f73fbf6fd1c475958c98b35d9169..8176c11c4e9b4d425de112260d1e290e78b87155 100644 --- a/app/assets/javascripts/projects/new_v2/components/app.vue +++ b/app/assets/javascripts/projects/new_v2/components/app.vue @@ -1,6 +1,7 @@