UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

38 lines • 1.88 kB
import * as Solid from 'solid-js'; import { RouterCore } from '@tanstack/router-core'; import { isServer } from '@tanstack/router-core/isServer'; import { getStoreFactory } from './routerStores'; import { primeRouterFromRegistry } from './registryTransfer'; import { noteRequest, releaseRequest } from './observe'; export const createRouter = (options) => { return new Router(options); }; export class Router extends RouterCore { constructor(options) { super(options, getStoreFactory); // The hydration-claiming boot (see registryTransfer). Router creation is // the client's natural pre-render moment: module code runs after the // document — and the registry entries the server's RouterProvider wrote — // have parsed, and always before hydrate(). Committing here keeps every // store write outside the hydration render, where it would desync the // claiming walk. Inert without entries: an SPA page has no registry, and // a Start app transfers through its own channel (`router.serverSsr`), // so the first missing entry falls through to unchanged behavior. if (!(isServer ?? this.isServer)) { primeRouterFromRegistry(this); // Solid's observe tier dates a navigation from its request and joins // it to the interaction it was requested in, both gone by the time a // blocked history notifies (see `noteRequest`). if (Solid.OBSERVE !== undefined) { const commitLocation = this.commitLocation; this.commitLocation = (opts) => { noteRequest(this); const committed = commitLocation(opts); releaseRequest(this); return committed; }; } } } } //# sourceMappingURL=router.js.map