{"record":{"id":"13e3640827bbf507","repo":"marmelab/react-admin","slug":"cannot-create-a-link-without-a-resource-you-must","errorCode":null,"errorMessage":"Cannot create a link without a resource. You must provide the resource name.","messagePattern":"Cannot create a link without a resource\\. You must provide the resource name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/routing/useCreatePath.ts","lineNumber":47,"sourceCode":" *            type: 'edit',\n *            resource: 'posts',\n *            id: record.id\n *         });\n *         navigate(link);\n *     };\n *\n *    return <button onClick={handleClick}>Edit Post</button>;\n * };\n */\nexport const useCreatePath = () => {\n    const basename = useBasename();\n    return useCallback(\n        ({ resource, id, type }: CreatePathParams): string => {\n            if (\n                ['list', 'create', 'edit', 'show'].includes(type) &&\n                !resource\n            ) {\n                throw new Error(\n                    'Cannot create a link without a resource. You must provide the resource name.'\n                );\n            }\n            switch (type) {\n                case 'list':\n                    return removeDoubleSlashes(`${basename}/${resource}`);\n                case 'create':\n                    return removeDoubleSlashes(\n                        `${basename}/${resource}/create`\n                    );\n                case 'edit': {\n                    if (id == null) {\n                        // maybe the id isn't defined yet\n                        // instead of throwing an error, fallback to list link\n                        return removeDoubleSlashes(`${basename}/${resource}`);\n                    }\n                    return removeDoubleSlashes(\n                        `${basename}/${resource}/${encodeURIComponent(id)}`","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/routing/useCreatePath.ts#L29-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Pass an explicit resource: createPath({ resource: 'posts', id, type: 'edit' }).","Derive the resource from context with useResourceContext(props) and guard before calling createPath.","Render/execute the link creation only after the resource value is known (e.g. after data loads or with a fallback resource)."],"exampleFix":"// before\nconst link = createPath({ id: record.id, type: 'edit' }); // throws\n\n// after\nconst link = createPath({ resource: 'posts', id: record.id, type: 'edit' });","handlingStrategy":"validation","validationCode":"const createPath = useCreatePath();\nconst typesNeedingResource = ['list', 'create', 'edit', 'show'];\nif (!resource && typesNeedingResource.includes(type)) {\n    throw new Error('createPath requires a resource for type ' + type);\n}\nconst path = createPath({ resource, id, type });","typeGuard":"const canCreatePath = (p: { resource?: string; type: string }) =>\n    !['list', 'create', 'edit', 'show'].includes(p.type) || !!p.resource;","tryCatchPattern":"try {\n    path = createPath({ resource, id, type });\n} catch (e) {\n    console.error('createPath failed: missing resource', e);\n    path = '#';\n}","preventionTips":["Make resource a required prop on custom link components.","Derive resource via useResourceContext instead of optional props.","Delay link creation until dynamic resource values are loaded."],"tags":["routing","validation","argument-error"],"backgroundTag":"missing-required-argument","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}