UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

103 lines (102 loc) 3.1 kB
import { useRouter } from "./useRouter.js"; import { useMatch } from "./useMatch.js"; import { useLoaderData } from "./useLoaderData.js"; import { useLoaderDeps } from "./useLoaderDeps.js"; import { useParams } from "./useParams.js"; import { useSearch } from "./useSearch.js"; import { useNavigate } from "./useNavigate.js"; import { useRouteContext } from "./useRouteContext.js"; import { createRoute } from "./route.js"; import warning from "tiny-warning"; //#region src/fileRoute.ts function createFileRoute(path) { if (typeof path === "object") return new FileRoute(path, { silent: true }).createRoute(path); return new FileRoute(path, { silent: true }).createRoute; } /** @deprecated It's no longer recommended to use the `FileRoute` class directly. Instead, use `createFileRoute('/path/to/file')(options)` to create a file route. */ var FileRoute = class { constructor(path, _opts) { this.path = path; this.createRoute = (options) => { if (process.env.NODE_ENV !== "production") warning(this.silent, "FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead."); const route = createRoute(options); route.isRoot = false; return route; }; this.silent = _opts?.silent; } }; /** @deprecated It's recommended not to split loaders into separate files. Instead, place the loader function in the the main route file, inside the `createFileRoute('/path/to/file)(options)` options. */ function FileRouteLoader(_path) { if (process.env.NODE_ENV !== "production") warning(false, `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`); return (loaderFn) => loaderFn; } var LazyRoute = class { constructor(opts) { this.useMatch = (opts) => { return useMatch({ select: opts?.select, from: this.options.id }); }; this.useRouteContext = (opts) => { return useRouteContext({ ...opts, from: this.options.id }); }; this.useSearch = (opts) => { return useSearch({ select: opts?.select, from: this.options.id }); }; this.useParams = (opts) => { return useParams({ select: opts?.select, from: this.options.id }); }; this.useLoaderDeps = (opts) => { return useLoaderDeps({ ...opts, from: this.options.id }); }; this.useLoaderData = (opts) => { return useLoaderData({ ...opts, from: this.options.id }); }; this.useNavigate = () => { return useNavigate({ from: useRouter().routesById[this.options.id].fullPath }); }; this.options = opts; } }; function createLazyRoute(id) { return (opts) => { return new LazyRoute({ id, ...opts }); }; } function createLazyFileRoute(id) { if (typeof id === "object") return new LazyRoute(id); return (opts) => new LazyRoute({ id, ...opts }); } //#endregion export { FileRoute, FileRouteLoader, LazyRoute, createFileRoute, createLazyFileRoute, createLazyRoute }; //# sourceMappingURL=fileRoute.js.map