marmelab/react-admin · error · Error
Cannot generate a link for a record without a resource. You
Error message
Cannot generate a link for a record without a resource. You must use useGetPathForRecordCallback within a ResourceContextProvider, or pass a resource parameter.
What it means
useGetPathForRecordCallback returns a callback that resolves a record's URL. Inside the callback it resolves the resource from the params, or falls back to the resource captured from the ResourceContext at hook time. When neither exists it throws, since generating a record link requires a resource name.
Source
Thrown at packages/ra-core/src/routing/useGetPathForRecordCallback.ts:24
import { useCreatePath } from './useCreatePath';
import { UseGetRouteForRecordOptions } from './useGetPathForRecord';
export const useGetPathForRecordCallback = <
RecordType extends RaRecord = RaRecord,
>(
options: UseGetPathForRecordCallbackOptions = {}
) => {
const resource = useResourceContext(options);
const resourceDefinitions = useResourceDefinitions();
const createPath = useCreatePath();
const canAccess = useCanAccessCallback();
return useCallback(
async (params: UseGetRouteForRecordOptions<RecordType>) => {
const { link, record } = params || {};
const finalResource = params.resource ?? resource;
if (!finalResource) {
throw new Error(
'Cannot generate a link for a record without a resource. You must use useGetPathForRecordCallback within a ResourceContextProvider, or pass a resource parameter.'
);
}
const resourceDefinition = resourceDefinitions[finalResource] ?? {};
if (record == null || link === false) {
return false;
}
// When the link prop is not provided, we infer a default value and check whether users
// can access it
if (link == null) {
// check if the user can access the show and edit pages in parallel
const [canAccessShow, canAccessEdit] = await Promise.all([
resourceDefinition.hasShow
? canAccess({
action: 'show',
resource: finalResource,View on GitHub (pinned to 051f511bb0)
Solutions
- Include resource in the callback params: getPath({ resource: 'posts', record }).
- Call the hook (and thus capture the context resource) inside a ResourceContextProvider subtree.
- Guard the call: only invoke the callback once the resource is known, or provide a default resource.
Example fix
// before
const getPath = useGetPathForRecordCallback();
const url = await getPath({ record }); // throws outside resource context
// after
const url = await getPath({ resource: 'posts', record }); Defensive patterns
Strategy: validation
Validate before calling
const getPath = useGetPathForRecordCallback();
const safeGetPath = (params) =>
(params.resource ?? resource)
? getPath(params)
: undefined;
const url = await safeGetPath({ record }); Type guard
const hasResourceParam = (p: { resource?: string }) => typeof p.resource === 'string' && p.resource.length > 0; Try / catch
try {
url = await getPath({ record });
} catch (e) {
console.warn('No resource for record path', e);
url = undefined;
} Prevention
- Always include resource in the callback params when used outside resource pages.
- Capture the context resource at hook time by calling the hook inside a ResourceContextProvider.
- Await the callback only after the record and resource are resolved.
When it happens
Trigger: Invoking the returned callback with ({ record }) and no resource in params while the hook was called outside a ResourceContextProvider; the resource prop/context being undefined at callback time (data not loaded); calling the callback on a custom page without resource context.
Common situations: Reusable row-link logic used on a dashboard; portaled components losing the ResourceContext; async handlers built at mount when context hadn't resolved; forgetting the resource key in the callback params object.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Cannot generate a link for a record without a resource. You
- useEditController requires an id prop or a route with an /:i
- <InfiniteList> was called outside of a ResourceContext and w
- useListController requires a non-empty resource prop or cont
- useShowController requires a non-empty resource prop or cont
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/701dc41a6662a09a.
Report an issue: GitHub.