@paretojs/core
The main entry point for Pareto’s runtime API.
import { Link, Await, ParetoErrorBoundary, useLoaderData, useRouter, defer, redirect, notFound, mergeHeadDescriptors,} from '@paretojs/core'Components
Section titled “Components”<Link>
Section titled “<Link>”Client-side navigation link. Intercepts clicks for same-origin navigation. See File-Based Routing for how routes are defined.
<Link href="/about">About</Link><Link href="/blog" prefetch="viewport">Blog</Link><Link href="/login" replace>Login</Link>| Prop | Type | Default | Description |
|---|---|---|---|
href | string | required | Target URL |
prefetch | 'hover' | 'viewport' | 'none' | 'hover' | Prefetch strategy |
replace | boolean | false | Replace history entry |
scroll | boolean | true | Scroll to top on navigation |
<Await>
Section titled “<Await>”Renders deferred data from defer(). Shows fallback until the promise resolves. See Streaming SSR for usage patterns and error handling.
<Await resolve={data.feed} fallback={<Skeleton />}> {(feed) => <Feed items={feed} />}</Await><ParetoErrorBoundary>
Section titled “<ParetoErrorBoundary>”React error boundary for catching render errors. Wrap any section of your UI that might throw. See Error Handling for usage patterns and nested boundary strategies.
<ParetoErrorBoundary fallback={({ error }) => <p>{error.message}</p>}> <RiskyComponent /></ParetoErrorBoundary>| Prop | Type | Description |
|---|---|---|
fallback | React.ComponentType<{ error: Error }> | Component to render when an error is caught |
children | ReactNode | Content to render normally |
useLoaderData<T>()
Section titled “useLoaderData<T>()”Access data returned by the route’s loader function. The generic type parameter provides type safety for the returned data.
const data = useLoaderData<{ user: User }>()useRouter()
Section titled “useRouter()”Access the router state and navigation methods. Useful for programmatic navigation, active link styling, and navigation state.
const { pathname, params, isNavigating, push, replace, back, prefetch } = useRouter()| Property | Type | Description |
|---|---|---|
pathname | string | Current URL path |
params | Record<string, string> | Dynamic route parameters |
isNavigating | boolean | true during navigation transitions |
push(url) | (url: string) => void | Navigate to URL (adds history entry) |
replace(url) | (url: string) => void | Navigate to URL (replaces history entry) |
back() | () => void | Navigate back in history |
prefetch(url) | (url: string) => void | Prefetch a route’s loader data |
Functions
Section titled “Functions”defer(data)
Section titled “defer(data)”Wrap loader return value for streaming. Resolved values are sent immediately; promises stream in via Suspense. See Streaming SSR for detailed usage.
return defer({ instant: { count: 42 }, streamed: fetchSlowData(),})redirect(url, status?)
Section titled “redirect(url, status?)”Throw in a loader to trigger an HTTP redirect. Default status: 302. See Redirect & 404 for common patterns like auth guards and URL migrations.
throw redirect('/login')throw redirect('/new-url', 301)notFound()
Section titled “notFound()”Throw in a loader to render not-found.tsx with 404 status. See Redirect & 404 for the difference between notFound() and throwing errors.
throw notFound()mergeHeadDescriptors(...descriptors)
Section titled “mergeHeadDescriptors(...descriptors)”Merge multiple HeadDescriptor objects. Used internally by the framework to merge head descriptors from root to page. You can use it in custom setups. See Head Management for how head merging works.
const merged = mergeHeadDescriptors(rootHead, layoutHead, pageHead)LoaderContext
Section titled “LoaderContext”The context object passed to every loader and action function. Provides access to the Express request/response and route parameters.
interface LoaderContext { req: Request // Express request res: Response // Express response params: Record<string, string>}RouteConfig
Section titled “RouteConfig”Per-route configuration exported from page.tsx. See Static Site Generation for SSG usage.
interface RouteConfig { render?: 'server' | 'static'}HeadDescriptor
Section titled “HeadDescriptor”The return type of head() functions in head.tsx files. See Head Management for merging behavior and OG tag examples.
interface HeadDescriptor { title?: string meta?: Record<string, string>[] link?: Record<string, string>[]}