diff --git a/code/core/src/manager-api/modules/url.ts b/code/core/src/manager-api/modules/url.ts index 67b94017b0bf..e6a76a0dad11 100644 --- a/code/core/src/manager-api/modules/url.ts +++ b/code/core/src/manager-api/modules/url.ts @@ -282,10 +282,15 @@ export const init: ModuleFn = (moduleArgs) => { globalsParam = globalsParam && `&globals=${globalsParam}`; customManagerParams = customManagerParams && `&${customManagerParams}`; customPreviewParams = customPreviewParams && `&${customPreviewParams}`; + const hashIndex = previewBase.indexOf('#'); + const previewBaseWithoutHash = + hashIndex === -1 ? previewBase : previewBase.slice(0, hashIndex); + const previewHash = hashIndex === -1 ? '' : previewBase.slice(hashIndex); + const separator = previewBaseWithoutHash.includes('?') ? '&' : '?'; return { managerHref: `${managerBase}?path=/${viewMode}/${refId ? `${refId}_` : ''}${storyId}${argsParam}${globalsParam}${customManagerParams}`, - previewHref: `${previewBase}?id=${storyId}&viewMode=${viewMode}${refParam}${argsParam}${refId ? '' : globalsParam}${customPreviewParams}`, + previewHref: `${previewBaseWithoutHash}${separator}id=${storyId}&viewMode=${viewMode}${refParam}${argsParam}${refId ? '' : globalsParam}${customPreviewParams}${previewHash}`, }; }, getQueryParam(key) {