@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
210 lines (209 loc) • 4.72 kB
JavaScript
import { useRouter } from "./useRouter.js";
import { Link } from "./link.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 { BaseRootRoute, BaseRoute, BaseRouteApi, notFound } from "@tanstack/router-core";
import { createComponent, mergeProps } from "solid-js/web";
//#region src/route.tsx
function getRouteApi(id) {
return new RouteApi({ id });
}
var RouteApi = class extends BaseRouteApi {
/**
* @deprecated Use the `getRouteApi` function instead.
*/
constructor({ id }) {
super({ id });
this.useMatch = (opts) => {
return useMatch({
select: opts?.select,
from: this.id
});
};
this.useRouteContext = (opts) => {
return useRouteContext({
...opts,
from: this.id
});
};
this.useSearch = (opts) => {
return useSearch({
select: opts?.select,
from: this.id
});
};
this.useParams = (opts) => {
return useParams({
select: opts?.select,
from: this.id
});
};
this.useLoaderDeps = (opts) => {
return useLoaderDeps({
...opts,
from: this.id,
strict: false
});
};
this.useLoaderData = (opts) => {
return useLoaderData({
...opts,
from: this.id,
strict: false
});
};
this.useNavigate = () => {
return useNavigate({ from: useRouter().routesById[this.id].fullPath });
};
this.notFound = (opts) => {
return notFound({
routeId: this.id,
...opts
});
};
this.Link = ((props) => {
const fullPath = useRouter().routesById[this.id].fullPath;
return createComponent(Link, mergeProps({ from: fullPath }, props));
});
}
};
var Route = class extends BaseRoute {
/**
* @deprecated Use the `createRoute` function instead.
*/
constructor(options) {
super(options);
this.useMatch = (opts) => {
return useMatch({
select: opts?.select,
from: this.id
});
};
this.useRouteContext = (opts) => {
return useRouteContext({
...opts,
from: this.id
});
};
this.useSearch = (opts) => {
return useSearch({
select: opts?.select,
from: this.id
});
};
this.useParams = (opts) => {
return useParams({
select: opts?.select,
from: this.id
});
};
this.useLoaderDeps = (opts) => {
return useLoaderDeps({
...opts,
from: this.id
});
};
this.useLoaderData = (opts) => {
return useLoaderData({
...opts,
from: this.id
});
};
this.useNavigate = () => {
return useNavigate({ from: this.fullPath });
};
this.Link = ((props) => {
const _self$ = this;
return createComponent(Link, mergeProps({ get from() {
return _self$.fullPath;
} }, props));
});
}
};
function createRoute(options) {
return new Route(options);
}
function createRootRouteWithContext() {
return (options) => {
return createRootRoute(options);
};
}
/**
* @deprecated Use the `createRootRouteWithContext` function instead.
*/
var rootRouteWithContext = createRootRouteWithContext;
var RootRoute = class extends BaseRootRoute {
/**
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
*/
constructor(options) {
super(options);
this.useMatch = (opts) => {
return useMatch({
select: opts?.select,
from: this.id
});
};
this.useRouteContext = (opts) => {
return useRouteContext({
...opts,
from: this.id
});
};
this.useSearch = (opts) => {
return useSearch({
select: opts?.select,
from: this.id
});
};
this.useParams = (opts) => {
return useParams({
select: opts?.select,
from: this.id
});
};
this.useLoaderDeps = (opts) => {
return useLoaderDeps({
...opts,
from: this.id
});
};
this.useLoaderData = (opts) => {
return useLoaderData({
...opts,
from: this.id
});
};
this.useNavigate = () => {
return useNavigate({ from: this.fullPath });
};
this.Link = ((props) => {
const _self$2 = this;
return createComponent(Link, mergeProps({ get from() {
return _self$2.fullPath;
} }, props));
});
}
};
function createRouteMask(opts) {
return opts;
}
var NotFoundRoute = class extends Route {
constructor(options) {
super({
...options,
id: "404"
});
}
};
function createRootRoute(options) {
return new RootRoute(options);
}
//#endregion
export { NotFoundRoute, RootRoute, Route, RouteApi, createRootRoute, createRootRouteWithContext, createRoute, createRouteMask, getRouteApi, rootRouteWithContext };
//# sourceMappingURL=route.js.map