marmelab/react-admin · error · Error

Cannot create a link without a resource. You must provide th

Error message

Cannot create a link without a resource. You must provide the resource name.

What it means

useCreatePath().createPath builds admin URLs from {resource, id, type}. For the 'list', 'create', 'edit' and 'show' types a resource name is mandatory to compose the path, so react-admin throws immediately when type is one of those and resource is falsy.

Source

Thrown at packages/ra-core/src/routing/useCreatePath.ts:47

 *            type: 'edit',
 *            resource: 'posts',
 *            id: record.id
 *         });
 *         navigate(link);
 *     };
 *
 *    return <button onClick={handleClick}>Edit Post</button>;
 * };
 */
export const useCreatePath = () => {
    const basename = useBasename();
    return useCallback(
        ({ resource, id, type }: CreatePathParams): string => {
            if (
                ['list', 'create', 'edit', 'show'].includes(type) &&
                !resource
            ) {
                throw new Error(
                    'Cannot create a link without a resource. You must provide the resource name.'
                );
            }
            switch (type) {
                case 'list':
                    return removeDoubleSlashes(`${basename}/${resource}`);
                case 'create':
                    return removeDoubleSlashes(
                        `${basename}/${resource}/create`
                    );
                case 'edit': {
                    if (id == null) {
                        // maybe the id isn't defined yet
                        // instead of throwing an error, fallback to list link
                        return removeDoubleSlashes(`${basename}/${resource}`);
                    }
                    return removeDoubleSlashes(
                        `${basename}/${resource}/${encodeURIComponent(id)}`

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Pass an explicit resource: createPath({ resource: 'posts', id, type: 'edit' }).
  2. Derive the resource from context with useResourceContext(props) and guard before calling createPath.
  3. Render/execute the link creation only after the resource value is known (e.g. after data loads or with a fallback resource).

Example fix

// before
const link = createPath({ id: record.id, type: 'edit' }); // throws

// after
const link = createPath({ resource: 'posts', id: record.id, type: 'edit' });
Defensive patterns

Strategy: validation

Validate before calling

const createPath = useCreatePath();
const typesNeedingResource = ['list', 'create', 'edit', 'show'];
if (!resource && typesNeedingResource.includes(type)) {
    throw new Error('createPath requires a resource for type ' + type);
}
const path = createPath({ resource, id, type });

Type guard

const canCreatePath = (p: { resource?: string; type: string }) =>
    !['list', 'create', 'edit', 'show'].includes(p.type) || !!p.resource;

Try / catch

try {
    path = createPath({ resource, id, type });
} catch (e) {
    console.error('createPath failed: missing resource', e);
    path = '#';
}

Prevention

When it happens

Trigger: Calling createPath({ type: 'edit', id: 1 }) without a resource prop; passing resource={undefined} due to an optional prop or empty variable; computing a link for a record before its resource field is populated.

Common situations: Custom Link/MenuItem components that hardcode type but forget resource; refactored components whose resource prop became optional; dynamic resources read from data that hasn't loaded yet (undefined at first render).

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


AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30). Data as JSON: /api/errors/13e3640827bbf507. Report an issue: GitHub.