UNPKG

@generouted/solid-router

Version:

Generated file-based routes for Solid Router and Vite

42 lines (39 loc) 1.35 kB
import { generatePath } from "./chunk-ZTW27XCD.js"; // src/client/hooks.ts import { useLocation, useMatch, useNavigate, useParams } from "@solidjs/router"; var hooks = () => { return { useParams: (path) => useParams(), useNavigate: () => { const navigate = useNavigate(); return (href, ...[options]) => { navigate(options?.params ? generatePath(href, options.params) : href, options); }; }, useMatch: (path, matchFilters) => { return useMatch(path, matchFilters); }, useModals: () => { const location = useLocation(); const navigate = useNavigate(); return { current: location.state?.modal || "", open: (path, options) => { const { at, state, ...opts } = options || {}; const pathname = options?.params ? generatePath(at || "", options.params || {}) : at; navigate(pathname || location.pathname, { ...opts, state: { ...location.state, ...state, modal: path } }); }, close: (options) => { const { at, state, ...opts } = options || {}; const pathname = options?.params ? generatePath(at || "", options.params || {}) : at; navigate(pathname || location.pathname, { ...opts, state: { ...location.state, ...state, modal: "" } }); } }; } }; }; export { hooks };