@tanstack/react-router
Version:
Modern and scalable routing for React applications
100 lines (99 loc) • 3.04 kB
JavaScript
import warning from "tiny-warning";
import { createRoute } from "./route.js";
import { useMatch } from "./useMatch.js";
import { useLoaderDeps } from "./useLoaderDeps.js";
import { useLoaderData } from "./useLoaderData.js";
import { useSearch } from "./useSearch.js";
import { useParams } from "./useParams.js";
import { useNavigate } from "./useNavigate.js";
import { useRouter } from "./useRouter.js";
function createFileRoute(path) {
return new FileRoute(path, {
silent: true
}).createRoute;
}
class FileRoute {
constructor(path, _opts) {
this.path = path;
this.createRoute = (options) => {
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 == null ? void 0 : _opts.silent;
}
}
function FileRouteLoader(_path) {
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;
}
class LazyRoute {
constructor(opts) {
this.useMatch = (opts2) => {
return useMatch({
select: opts2 == null ? void 0 : opts2.select,
from: this.options.id,
structuralSharing: opts2 == null ? void 0 : opts2.structuralSharing
});
};
this.useRouteContext = (opts2) => {
return useMatch({
from: this.options.id,
select: (d) => (opts2 == null ? void 0 : opts2.select) ? opts2.select(d.context) : d.context
});
};
this.useSearch = (opts2) => {
return useSearch({
select: opts2 == null ? void 0 : opts2.select,
structuralSharing: opts2 == null ? void 0 : opts2.structuralSharing,
from: this.options.id
});
};
this.useParams = (opts2) => {
return useParams({
select: opts2 == null ? void 0 : opts2.select,
structuralSharing: opts2 == null ? void 0 : opts2.structuralSharing,
from: this.options.id
});
};
this.useLoaderDeps = (opts2) => {
return useLoaderDeps({ ...opts2, from: this.options.id });
};
this.useLoaderData = (opts2) => {
return useLoaderData({ ...opts2, from: this.options.id });
};
this.useNavigate = () => {
const router = useRouter();
return useNavigate({ from: router.routesById[this.options.id].fullPath });
};
this.options = opts;
this.$$typeof = Symbol.for("react.memo");
}
}
function createLazyRoute(id) {
return (opts) => {
return new LazyRoute({
id,
...opts
});
};
}
function createLazyFileRoute(id) {
return (opts) => new LazyRoute({ id, ...opts });
}
export {
FileRoute,
FileRouteLoader,
LazyRoute,
createFileRoute,
createLazyFileRoute,
createLazyRoute
};
//# sourceMappingURL=fileRoute.js.map