Deep Research and Posterverse: the open tab is in the address, written by the site's router
- Both apps are told urlOwner 'host' and send 'dxm-address' when their open tab changes; the page's router writes it: a tab click is a new history entry, the app's first paint replaces the current one. - So a shared link or a reload opens the same tab, and Back, Forward and the language switch keep it.
This commit is contained in:
parent
7588047ad9
commit
be8f6913a3
2 changed files with 30 additions and 1 deletions
|
|
@ -99,6 +99,18 @@ function onLanguageRequest(e: Event) {
|
|||
navigateTo(url.pathname + url.search + url.hash)
|
||||
}
|
||||
|
||||
// THE ADDRESS (shareable pages): this site's router owns the address, so the app is told urlOwner 'host' and, when the
|
||||
// open tab changes, it sends a 'dxm-address' {href, push} instead of writing history itself. A reader's tab click is a
|
||||
// new history entry (push); the app's first paint replaces the current one (so a shared link or a reload keeps the
|
||||
// tab). The router writes it, so Back, Forward and the language switch keep the tab; Back/Forward never send one.
|
||||
const router = useRouter()
|
||||
function onAddress(e: Event) {
|
||||
const d = (e as CustomEvent<{ href?: string, push?: boolean }>).detail
|
||||
if (!d || typeof d.href !== 'string' || !d.href.startsWith('/') || d.href.startsWith('//')) return
|
||||
if (d.push) router.push(d.href).catch(() => {})
|
||||
else router.replace(d.href).catch(() => {})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
gallery = document.createElement('doxa-maps-spa')
|
||||
// Every embed URL is built at RUNTIME from the origin serving this page, so the same build works on
|
||||
|
|
@ -116,10 +128,13 @@ onMounted(() => {
|
|||
const galleryConfig: Record<string, unknown> = {}
|
||||
// The keyless MapLibre engine, always: the app needs no token and no setting.
|
||||
galleryConfig.provider = 'maplibre'
|
||||
// the site's router writes the address (onAddress, above)
|
||||
galleryConfig.urlOwner = 'host'
|
||||
gallery.setAttribute('provider', 'maplibre')
|
||||
gallery.setAttribute('profile-config', JSON.stringify(galleryConfig))
|
||||
gallery.addEventListener('tab-change', onTabChange)
|
||||
gallery.addEventListener('doxa-language-request', onLanguageRequest)
|
||||
gallery.addEventListener('dxm-address', onAddress)
|
||||
host.value?.appendChild(gallery)
|
||||
// its script, revalidated (above) and then added at its plain address, once per page load
|
||||
if (!customElements.get('doxa-maps-spa') && !document.querySelector(`script[src="${GALLERY_SCRIPT}"]`)) {
|
||||
|
|
|
|||
|
|
@ -98,6 +98,18 @@ function onLanguageRequest(e: Event) {
|
|||
navigateTo(url.pathname + url.search + url.hash)
|
||||
}
|
||||
|
||||
// THE ADDRESS (shareable pages): this site's router owns the address, so the app is told urlOwner 'host' and, when the
|
||||
// open tab changes, it sends a 'dxm-address' {href, push} instead of writing history itself. A reader's tab click is a
|
||||
// new history entry (push); the app's first paint replaces the current one (so a shared link or a reload keeps the
|
||||
// tab). The router writes it, so Back, Forward and the language switch keep the tab; Back/Forward never send one.
|
||||
const router = useRouter()
|
||||
function onAddress(e: Event) {
|
||||
const d = (e as CustomEvent<{ href?: string, push?: boolean }>).detail
|
||||
if (!d || typeof d.href !== 'string' || !d.href.startsWith('/') || d.href.startsWith('//')) return
|
||||
if (d.push) router.push(d.href).catch(() => {})
|
||||
else router.replace(d.href).catch(() => {})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
shell = document.createElement('posterverse-app')
|
||||
// Every embed URL is built at RUNTIME from the origin serving this page, so the same build works on
|
||||
|
|
@ -112,11 +124,13 @@ onMounted(() => {
|
|||
shell.setAttribute('home-href', homeHref())
|
||||
shell.setAttribute('home-label', homeLabel())
|
||||
// The keyless MapLibre engine, always: the app needs no token and no setting.
|
||||
const shellConfig: Record<string, unknown> = { provider: 'maplibre' }
|
||||
// urlOwner 'host': the site's router writes the address (onAddress, above)
|
||||
const shellConfig: Record<string, unknown> = { provider: 'maplibre', urlOwner: 'host' }
|
||||
shell.setAttribute('provider', 'maplibre')
|
||||
shell.setAttribute('profile-config', JSON.stringify(shellConfig))
|
||||
shell.addEventListener('tab-change', onTabChange)
|
||||
shell.addEventListener('doxa-language-request', onLanguageRequest)
|
||||
shell.addEventListener('dxm-address', onAddress)
|
||||
host.value?.appendChild(shell)
|
||||
// its script, revalidated (above) and then added at its plain address, once per page load
|
||||
if (!customElements.get('posterverse-app') && !document.querySelector(`script[src="${POSTERVERSE_SCRIPT}"]`)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue