@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
169 lines • 5.22 kB
JSX
import { BaseRootRoute, BaseRoute, BaseRouteApi, notFound, } from '@tanstack/router-core';
import { Link } from './link';
import { useLoaderData } from './useLoaderData';
import { useLoaderDeps } from './useLoaderDeps';
import { useParams } from './useParams';
import { useSearch } from './useSearch';
import { useNavigate } from './useNavigate';
import { useMatch } from './useMatch';
import { useRouteContext } from './useRouteContext';
import { useRouter } from './useRouter';
export function getRouteApi(id) {
return new RouteApi({ id });
}
export class RouteApi 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 = () => {
const router = useRouter();
return useNavigate({ from: router.routesById[this.id].fullPath });
};
this.notFound = (opts) => {
return notFound({ routeId: this.id, ...opts });
};
this.Link = ((props) => {
const router = useRouter();
const fullPath = router.routesById[this.id].fullPath;
return <Link from={fullPath} {...props}/>;
});
}
}
export class Route 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) => {
return <Link from={this.fullPath} {...props}/>;
});
}
}
export function createRoute(options) {
return new Route(options);
}
export function createRootRouteWithContext() {
return (options) => {
return createRootRoute(options);
};
}
/**
* @deprecated Use the `createRootRouteWithContext` function instead.
*/
export const rootRouteWithContext = createRootRouteWithContext;
export class RootRoute 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) => {
return <Link from={this.fullPath} {...props}/>;
});
}
}
export function createRouteMask(opts) {
return opts;
}
export class NotFoundRoute extends Route {
constructor(options) {
super({
...options,
id: '404',
});
}
}
export function createRootRoute(options) {
return new RootRoute(options);
}
//# sourceMappingURL=route.jsx.map