ApplicationEnvironment
Deployment callbacks for URL resolution, document handoffs, and the initial document script.
Compatibility
Import from @kasperrt/smolter/react @kasperrt/smolter/preact
Signature
interface ApplicationEnvironment {
resolveURL?: (url: URL) => URL;
isDocumentHandoff?: (from: URL, to: URL) => boolean;
leaveDocument?: (destination: URL) => void;
entryScript?: string;
}Fields
resolveURL receives a URL and returns its deployed destination. isDocumentHandoff receives the current and destination URLs and decides whether a document link uses the configured handoff. leaveDocument performs that handoff; without it, navigation uses location.assign. entryScript supplies the inline bootstrap source rendered by Scripts. Every field is optional.
Configuration
Import the type from the Preact entry and configure the environment through the optional client entry before mounting. Configuration is shared by application instances in the same module environment. It is not a route-specific setting.
import type { ApplicationEnvironment } from "@kasperrt/smolter/preact";
import { configureApplication } from "@kasperrt/smolter/preact/client";
const environment: ApplicationEnvironment = {
resolveURL(url) {
if (url.origin === "https://legacy.example") {
return new URL(url.pathname + url.search + url.hash, location.origin);
}
return url;
},
};
configureApplication(environment);Default behavior
With no configuration, URLs are unchanged. Ordinary external links keep browser handling. A configured document handoff prevents the anchor default and calls leaveDocument. These callbacks do not declare routes or install a server endpoint.
Fields
resolveURL
resolveURL?: (url: URL) => URL;isDocumentHandoff
isDocumentHandoff?: (from: URL, to: URL) => boolean;leaveDocument
leaveDocument?: (destination: URL) => void;entryScript
entryScript?: string;