UNPKG

piral-core

Version:

The core library for creating a Piral instance.

36 lines 1.29 kB
import * as React from 'react'; import { useGlobalState } from '../hooks'; import { createRouteMatcher } from '../utils'; import { useRouteFilter } from '../../app.codegen'; function useShellRoutes() { const routes = useGlobalState((s) => s.routes); return React.useMemo(() => Object.entries(routes).map(([path, Component]) => ({ path, Component, meta: Component?.meta || {}, matcher: createRouteMatcher(path), })), [routes]); } function usePiletRoutes() { const pages = useGlobalState((s) => s.registry.pages); return React.useMemo(() => Object.entries(pages).map(([path, entry]) => ({ path, Component: entry.component, meta: entry.meta, matcher: createRouteMatcher(path), })), [pages]); } function useRoutes() { const shellRoutes = useShellRoutes(); const piletRoutes = usePiletRoutes(); return useRouteFilter([...shellRoutes, ...piletRoutes]); } /** * The component for defining the exclusive routes to be used. */ export const PiralRoutes = ({ NotFound, RouteSwitch, ...props }) => { const paths = useRoutes(); return React.createElement(RouteSwitch, { NotFound: NotFound, paths: paths, ...props }); }; PiralRoutes.displayName = 'Routes'; //# sourceMappingURL=PiralRoutes.js.map