37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
|
import { setActiveNavItem } from "./set-active-nav-item";
|
||
|
|
||
|
export async function initFirstLoadRouting(store, router, baseUrl, siteName) {
|
||
|
const decoupled_origin = JSON.parse(window.localStorage.getItem('decoupled_origin'));
|
||
|
|
||
|
if(decoupled_origin) {
|
||
|
await store.fetchContentData(baseUrl + decoupled_origin.url);
|
||
|
router.push(decoupled_origin.url);
|
||
|
window.localStorage.removeItem("decoupled_origin");
|
||
|
document.title = store.pageTitle;
|
||
|
setActiveNavItem(store.contentType, decoupled_origin.url);
|
||
|
} else {
|
||
|
document.title = siteName;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function handleClickableElements(clickableElements, store, router, baseUrl, siteName, mapStore) {
|
||
|
for (const link of clickableElements) {
|
||
|
let href = link.href || link.dataset.href;
|
||
|
if (href.startsWith(baseUrl)) href = href.replace(baseUrl, '');
|
||
|
|
||
|
link.onclick = async function (e) {
|
||
|
router.push(href);
|
||
|
if (href !== window.location.pathname) {
|
||
|
if (href === '/') {
|
||
|
store.resetStore(true);
|
||
|
document.title = siteName;
|
||
|
mapStore.resetMap();
|
||
|
} else {
|
||
|
await store.fetchContentData(baseUrl + href);
|
||
|
document.title = store.pageTitle;
|
||
|
}
|
||
|
setActiveNavItem(store.contentType, href);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|