UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

1 lines • 6.21 kB
{"version":3,"file":"router.cjs","names":[],"sources":["../../src/router.ts"],"sourcesContent":["import * as Solid from 'solid-js'\nimport { RouterCore } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { getStoreFactory } from './routerStores'\nimport { primeRouterFromRegistry } from './registryTransfer'\nimport { noteRequest, releaseRequest } from './observe'\nimport type { RouterHistory } from '@tanstack/history'\nimport type {\n AnyRoute,\n CreateRouterFn,\n RouterConstructorOptions,\n TrailingSlashOption,\n} from '@tanstack/router-core'\nimport type {\n ErrorRouteComponent,\n NotFoundRouteComponent,\n RouteComponent,\n} from './route'\nimport type { JSX } from '@solidjs/web'\n\ndeclare module '@tanstack/router-core' {\n export interface RouterOptionsExtensions {\n /**\n * The default `component` a route should use if no component is provided.\n *\n * @default Outlet\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)\n */\n defaultComponent?: RouteComponent\n /**\n * The default `errorComponent` a route should use if no error component is provided.\n *\n * @default ErrorComponent\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)\n */\n defaultErrorComponent?: ErrorRouteComponent\n /**\n * The default `pendingComponent` a route should use if no pending component is provided.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)\n */\n defaultPendingComponent?: RouteComponent\n /**\n * The default `notFoundComponent` a route should use if no notFound component is provided.\n *\n * @default NotFound\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)\n */\n defaultNotFoundComponent?: NotFoundRouteComponent\n /**\n * A component that will be used to wrap the entire router.\n *\n * This is useful for providing a context to the entire router.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#wrap-property)\n */\n Wrap?: (props: { children: any }) => JSX.Element\n /**\n * A component that will be used to wrap the inner contents of the router.\n *\n * This is useful for providing a context to the inner contents of the router where you also need access to the router context and hooks.\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#innerwrap-property)\n */\n InnerWrap?: (props: { children: any }) => JSX.Element\n\n /**\n * The default `onCatch` handler for errors caught by the Router ErrorBoundary\n *\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultoncatch-property)\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#handling-errors-with-routeoptionsoncatch)\n */\n defaultOnCatch?: (error: Error) => void\n }\n}\n\nexport const createRouter: CreateRouterFn = (options) => {\n return new Router(options)\n}\n\nexport class Router<\n in out TRouteTree extends AnyRoute,\n in out TTrailingSlashOption extends TrailingSlashOption = 'never',\n in out TDefaultStructuralSharingOption extends boolean = false,\n in out TRouterHistory extends RouterHistory = RouterHistory,\n in out TDehydrated extends Record<string, any> = Record<string, any>,\n> extends RouterCore<\n TRouteTree,\n TTrailingSlashOption,\n TDefaultStructuralSharingOption,\n TRouterHistory,\n TDehydrated\n> {\n constructor(\n options: RouterConstructorOptions<\n TRouteTree,\n TTrailingSlashOption,\n TDefaultStructuralSharingOption,\n TRouterHistory,\n TDehydrated\n >,\n ) {\n super(options, getStoreFactory)\n // The hydration-claiming boot (see registryTransfer). Router creation is\n // the client's natural pre-render moment: module code runs after the\n // document — and the registry entries the server's RouterProvider wrote —\n // have parsed, and always before hydrate(). Committing here keeps every\n // store write outside the hydration render, where it would desync the\n // claiming walk. Inert without entries: an SPA page has no registry, and\n // a Start app transfers through its own channel (`router.serverSsr`),\n // so the first missing entry falls through to unchanged behavior.\n if (!(isServer ?? this.isServer)) {\n primeRouterFromRegistry(this)\n // Solid's observe tier dates a navigation from its request and joins\n // it to the interaction it was requested in, both gone by the time a\n // blocked history notifies (see `noteRequest`).\n if (Solid.OBSERVE !== undefined) {\n const commitLocation = this.commitLocation\n this.commitLocation = (opts) => {\n noteRequest(this)\n const committed = commitLocation(opts)\n releaseRequest(this)\n return committed\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;AA+EA,IAAa,gBAAgC,YAAY;CACvD,OAAO,IAAI,OAAO,OAAO;AAC3B;AAEA,IAAa,SAAb,cAMU,sBAAA,WAMR;CACA,YACE,SAOA;EACA,MAAM,SAAS,qBAAA,eAAe;EAS9B,IAAI,EAAE,+BAAA,YAAY,KAAK,WAAW;GAChC,yBAAA,wBAAwB,IAAI;GAI5B,IAAI,SAAM,YAAY,KAAA,GAAW;IAC/B,MAAM,iBAAiB,KAAK;IAC5B,KAAK,kBAAkB,SAAS;KAC9B,gBAAA,YAAY,IAAI;KAChB,MAAM,YAAY,eAAe,IAAI;KACrC,gBAAA,eAAe,IAAI;KACnB,OAAO;IACT;GACF;EACF;CACF;AACF"}