You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
const routeConfigs = {
|
|
overview: { titleKey: "page.overview", partial: "/legacy/assets/partials/overview.html" },
|
|
ports: { titleKey: "page.ports", partial: "/legacy/assets/partials/ports.html" },
|
|
terminal: { titleKey: "page.terminal", partial: "/legacy/assets/partials/terminal.html" },
|
|
sessions: { titleKey: "page.sessions", partial: "/legacy/assets/partials/sessions.html" },
|
|
cabling: { titleKey: "page.cabling", partial: "/legacy/assets/partials/cabling.html" },
|
|
events: { titleKey: "page.events", partial: "/legacy/assets/partials/events.html" },
|
|
system: { titleKey: "page.system", partial: "/legacy/assets/partials/system.html" },
|
|
example: { titleKey: "page.example", partial: "/legacy/assets/partials/example.html" },
|
|
};
|
|
|
|
export function getRouteConfig(routeName) {
|
|
return routeConfigs[routeName] || routeConfigs.overview;
|
|
}
|
|
|
|
export function getRouteFromHash() {
|
|
const hash = window.location.hash.replace(/^#\/?/, "");
|
|
return routeConfigs[hash] ? hash : "overview";
|
|
}
|
|
|
|
export function navigateTo(routeName) {
|
|
const nextRoute = routeConfigs[routeName] ? routeName : "overview";
|
|
if (getRouteFromHash() === nextRoute) {
|
|
window.dispatchEvent(new HashChangeEvent("hashchange"));
|
|
return;
|
|
}
|
|
|
|
window.location.hash = nextRoute;
|
|
}
|
|
|
|
export async function loadPartial(routeName) {
|
|
const config = getRouteConfig(routeName);
|
|
const response = await fetch(config.partial, { cache: "no-cache" });
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`failed to load partial: ${config.partial}`);
|
|
}
|
|
|
|
return response.text();
|
|
}
|
|
|