Skip to content

@paretojs/core

The main entry point for Pareto’s runtime API.

import {
Link,
Await,
ParetoErrorBoundary,
useLoaderData,
useRouter,
defer,
redirect,
notFound,
mergeHeadDescriptors,
} from '@paretojs/core'

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>
PropTypeDefaultDescription
hrefstringrequiredTarget URL
prefetch'hover' | 'viewport' | 'none''hover'Prefetch strategy
replacebooleanfalseReplace history entry
scrollbooleantrueScroll to top on navigation

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>

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>
PropTypeDescription
fallbackReact.ComponentType<{ error: Error }>Component to render when an error is caught
childrenReactNodeContent to render normally

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 }>()

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()
PropertyTypeDescription
pathnamestringCurrent URL path
paramsRecord<string, string>Dynamic route parameters
isNavigatingbooleantrue during navigation transitions
push(url)(url: string) => voidNavigate to URL (adds history entry)
replace(url)(url: string) => voidNavigate to URL (replaces history entry)
back()() => voidNavigate back in history
prefetch(url)(url: string) => voidPrefetch a route’s loader 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(),
})

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)

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()

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)

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>
}

Per-route configuration exported from page.tsx. See Static Site Generation for SSG usage.

interface RouteConfig {
render?: 'server' | 'static'
}

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>[]
}