{"record":{"id":"b5e841c485f3feb4","repo":"marmelab/react-admin","slug":"useeditcontroller-requires-an-id-prop-or-a-route-w","errorCode":null,"errorMessage":"useEditController requires an id prop or a route with an /:id? parameter.","messagePattern":"useEditController requires an id prop or a route with an /:id\\? parameter\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/edit/useEditController.ts","lineNumber":87,"sourceCode":"        );\n    }\n    const { isPending: isPendingAuthenticated } = useAuthenticated({\n        enabled: !disableAuthentication,\n    });\n\n    const { isPending: isPendingCanAccess } = useRequireAccess<RecordType>({\n        action: 'edit',\n        resource,\n        enabled: !disableAuthentication && !isPendingAuthenticated,\n    });\n\n    const getRecordRepresentation = useGetRecordRepresentation(resource);\n    const translate = useTranslate();\n    const notify = useNotify();\n    const redirect = useRedirect();\n    const { id: routeId } = useParams<{ id?: string }>();\n    if (!routeId && !propsId) {\n        throw new Error(\n            'useEditController requires an id prop or a route with an /:id? parameter.'\n        );\n    }\n    const id = propsId ?? routeId;\n\n    const { meta: queryMeta, ...otherQueryOptions } = queryOptions;\n    const {\n        meta: mutationMeta,\n        onSuccess,\n        onError,\n        ...otherMutationOptions\n    } = mutationOptions;\n\n    if (\n        (queryMeta || mutationMeta) &&\n        JSON.stringify(queryMeta) !== JSON.stringify(mutationMeta) &&\n        redirectTo === false\n    ) {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/edit/useEditController.ts#L69-L105","documentation":"useEditController needs a record id to fetch and edit: it takes the id prop and falls back to the :id route parameter via useParams. If neither the id prop nor a route containing an /:id? segment is present, it cannot load a record and throws. Note the same hook can throw this even when the resource is correct (unlike error 3).","triggerScenarios":"Rendering <Edit> on a route that lacks an :id parameter (e.g. path=\"posts/edit\" instead of \"posts/:id/edit\"), or calling useEditController without an id prop outside a parameterized route.","commonSituations":"Custom <Route path=\"posts/edit\"> definitions missing the :id segment; using useEditController in a modal that doesn't pass the record id; upgrading react-admin and moving Edit off the standard Resource route so useParams no longer supplies the id.","solutions":["Pass the id explicitly: `<Edit resource=\"posts\" id={recordId}>`.","Fix the route path to include the id parameter: `<Route path=\"posts/:id/edit\">` or register via `<Resource name=\"posts\" edit={PostEdit}>` so the default :id route is generated.","Ensure react-router context exists (component rendered inside the Admin router) so useParams can read :id.","If editing a freshly created record, redirect to the edit route with the new id instead of a bare edit path."],"exampleFix":"// before\n<Route path=\"posts/edit\" element={<PostEdit />} />\n\n// after\n<Route path=\"posts/:id/edit\" element={<PostEdit />} />","handlingStrategy":"validation","validationCode":"// Confirm an id exists before rendering the edit view\nconst { id: routeId } = useParams<{ id?: string }>();\nconst id = propsId ?? routeId;\nif (!id) throw new Error('Edit view requires an id prop or an /:id route parameter');","typeGuard":"function hasEditId(routeId?: string, propsId?: string | number): routeId is string {\n  return Boolean(routeId ?? propsId);\n}","tryCatchPattern":"// Pre-validate before rendering the controller:\nconst id = propsId ?? routeId;\nif (!hasEditId(routeId, propsId)) {\n  return <Navigate to=\"/\" replace />; // or show an error page\n}\nconst controller = useEditController({ resource, id });","preventionTips":["Always include :id in custom edit route paths (e.g. posts/:id/edit).","Pass an explicit id prop when rendering <Edit> in modals or non-route contexts.","Redirect to the edit route with the new record id after creation.","Keep Edit views registered via <Resource name=\"...\" edit={...}> so standard :id routes are generated."],"tags":["react-admin","routing","controller","missing-parameter"],"backgroundTag":"missing-route-parameter","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}