{"record":{"id":"f806b2c3d820c5be","repo":"ionic-team/ionic-framework","slug":"removeview-was-not-found","errorCode":null,"errorMessage":"removeView was not found","messagePattern":"removeView was not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/src/components/nav/nav.tsx","lineNumber":700,"sourceCode":"      this.failed(rejectReason, ti);\n    }\n    this.isTransitioning = false;\n    this.nextTrns();\n  }\n\n  private prepareTI(ti: TransitionInstruction) {\n    const viewsLength = this.views.length;\n\n    ti.opts ??= {};\n    ti.opts.delegate ??= this.delegate;\n\n    if (ti.removeView !== undefined) {\n      assert(ti.removeStart !== undefined, 'removeView needs removeStart');\n      assert(ti.removeCount !== undefined, 'removeView needs removeCount');\n\n      const index = this.views.indexOf(ti.removeView);\n      if (index < 0) {\n        throw new Error('removeView was not found');\n      }\n      ti.removeStart! += index;\n    }\n    if (ti.removeStart !== undefined) {\n      if (ti.removeStart < 0) {\n        ti.removeStart = viewsLength - 1;\n      }\n      if (ti.removeCount! < 0) {\n        ti.removeCount = viewsLength - ti.removeStart;\n      }\n      ti.leavingRequiresTransition = ti.removeCount! > 0 && ti.removeStart + ti.removeCount! === viewsLength;\n    }\n\n    if (ti.insertViews) {\n      // allow -1 to be passed in to auto push it on the end\n      // and clean up the index if it's larger then the size of the stack\n      if (ti.insertStart! < 0 || ti.insertStart! > viewsLength) {\n        ti.insertStart = viewsLength;","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/ionic-team/ionic-framework/blob/625f9c38ad8c5db8a6c12df5c1622a36da90f9e3/core/src/components/nav/nav.tsx#L682-L718","documentation":"Thrown in IonNav.prepareTI() when a TransitionInstruction carries a `removeView` (a ViewController passed to `popTo(viewController)`) but that ViewController is not present in `this.views` (`indexOf` returns -1). The nav cannot compute a removal range relative to a view it does not own.","triggerScenarios":"Calling `nav.popTo(viewController)` where `viewController` was never inserted into this nav, was already removed, or belongs to a different nav instance. `popTo` only sets `removeView` when passed an object with a `.component` property (a ViewController).","commonSituations":"Caching a ViewController reference across navigations and reusing it after it was popped/destroyed; calling popTo with a view from a sibling/parent IonNav; mixing router-managed and manually-pushed views so the reference is stale.","solutions":["Pass an index instead of a ViewController to `popTo(index)` if you are unsure the view reference is still live.","Before calling `popTo(viewController)`, verify the view is still in this nav: `(await nav.getByIndex(await nav.getLength()-1))` lookup or compare against `nav.getViews()`.","Do not reuse a ViewController instance after it has been removed; fetch a fresh reference from the nav.","Ensure the same IonNav instance that inserted the view is the one you popTo."],"exampleFix":"// before\nawait nav.popTo(cachedViewController);\n// after\nconst views = nav.getViews();\nconst idx = views.indexOf(cachedViewController);\nif (idx >= 0) {\n  await nav.popTo(idx);\n}","handlingStrategy":"validation","validationCode":"// Validate the controller still belongs to this nav before popTo(viewController)\nconst views = nav.getViews();\nif (!views.includes(viewController)) {\n  throw new Error('ViewController is not in this nav; cannot popTo it.');\n}\nawait nav.popTo(views.indexOf(viewController));","typeGuard":"function viewBelongsToNav(nav: HTMLIonNavElement, view: ViewController): boolean {\n  return nav.getViews().includes(view);\n}","tryCatchPattern":"try {\n  await nav.popTo(viewController);\n} catch (e) {\n  if ((e as Error).message === 'removeView was not found') {\n    // fall back to popping to an index instead of a stale controller\n    await nav.popTo(await nav.getLength() - 1);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Prefer index-based popTo over ViewController-based when references may be stale.","Do not retain ViewController references after they are popped.","Verify ownership with nav.getViews().includes(view) before popTo."],"tags":["core","ion-nav","navigation","view-controller"],"backgroundTag":null,"analyzedSha":"625f9c38ad8c5db8a6c12df5c1622a36da90f9e3","analyzedAt":"2026-08-12T16:00:25.413Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}