{"record":{"id":"a4a7c864dc940651","repo":"appsmithorg/appsmith","slug":"missing-basepageid-if-you-are-trying-to-set-href","errorCode":null,"errorMessage":"Missing basePageId. If you are trying to set href inside a react component use the 'useHref' hook.","messagePattern":"Missing basePageId\\. If you are trying to set href inside a react component use the 'useHref' hook\\.","errorType":"exception","errorClass":"URIError","httpStatus":null,"severity":"error","filePath":"app/client/src/ce/entities/URLRedirect/URLAssembly.ts","lineNumber":332,"sourceCode":"\n    const formattedParams = {\n      staticApplicationSlug: applicationUniqueSlug,\n      staticPageSlug: pageSlug,\n      baseApplicationId: this.appParams.baseApplicationId,\n      basePageId: PLACEHOLDER_PAGE_SLUG,\n    };\n\n    return generatePath(urlPattern, formattedParams).toLowerCase();\n  }\n\n  resolveEntityIdForApp(builderParams: URLBuilderParams) {\n    const basePageId =\n      builderParams.basePageId ||\n      builderParams?.baseParentEntityId ||\n      this.currentBasePageId;\n\n    if (!basePageId) {\n      throw new URIError(\n        \"Missing basePageId. If you are trying to set href inside a react component use the 'useHref' hook.\",\n      );\n    }\n\n    return basePageId;\n  }\n\n  resolveEntityId(builderParams: URLBuilderParams): string {\n    return this.resolveEntityIdForApp(builderParams);\n  }\n\n  /**\n   * @throws {URIError}\n   * @param builderParams\n   * @param mode\n   * @returns URL string\n   */\n  build(builderParams: URLBuilderParams, mode: APP_MODE = APP_MODE.EDIT) {","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/src/ce/entities/URLRedirect/URLAssembly.ts#L314-L350","documentation":"Thrown by URLAssembly.resolveEntityIdForApp() when resolving the entity (page) id for URL building. It tries builderParams.basePageId, then builderParams.baseParentEntityId, then this.currentBasePageId; if all three are falsy it throws a URIError telling the caller to use the useHref hook, because outside React context there is no ambient currentBasePageId to fall back on.","triggerScenarios":"Calling resolveEntityIdForApp()/resolveEntityId() (or a builder that uses them) outside a component where basePageId/baseParentEntityId are not supplied AND the URLAssembly instance has no currentBasePageId set — typically building an href from a plain module/saga/utility rather than from a React component.","commonSituations":"Generating a page href in a Redux saga, a selector, or a non-React utility where the ambient page id is unavailable; refactoring href construction out of a component and dropping the pageId argument; calling the URL builder before the current page is loaded.","solutions":["From inside a React component, use the useHref hook (as the message directs) so the ambient page context supplies basePageId.","When calling the builder imperatively, pass basePageId (or baseParentEntityId) explicitly in URLBuilderParams.","Ensure the URLAssembly instance's currentBasePageId is set (e.g. via init/setCurrent) before resolving if you manage the instance yourself.","Defer URL resolution until the page context is available rather than resolving at module-load time."],"exampleFix":"// before (saga/utility, no page context)\nconst href = urlBuilder.build({ pageId })\n// throws: Missing basePageId...\n\n// after (in a component)\nconst href = useHref({ pageId })\n// or pass it explicitly:\nconst href = urlBuilder.build({ pageId, basePageId: currentPageId })","handlingStrategy":"type-guard","validationCode":"function resolveBuilderParams(p: URLBuilderParams, currentBasePageId?: string) {\n  const basePageId = p.basePageId || p.baseParentEntityId || currentBasePageId;\n  if (!basePageId) throw new Error('Pass basePageId or call from a component via useHref.');\n  return { ...p, basePageId };\n}","typeGuard":"function hasBasePageId(p: URLBuilderParams): p is URLBuilderParams & { basePageId: string } {\n  return Boolean(p.basePageId || p.baseParentEntityId);\n}","tryCatchPattern":"try { return builder.resolveEntityId(params); } catch (e) {\n  if (/Missing basePageId/i.test(e.message)) return useHref(params); // only valid inside a component\n  throw e;\n}","preventionTips":["Prefer the useHref hook inside components so page context is ambient.","Pass basePageId explicitly whenever calling the builder from a saga/utility.","Set URLAssembly.currentBasePageId at route entry so non-component callers have a fallback."],"tags":["react","routing","url-building","context","typescript"],"backgroundTag":null,"analyzedSha":"8cd9021c24cdbea1c3c12c966073708e83db60c2","analyzedAt":"2026-08-12T22:14:19.293Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}