{"record":{"id":"4b70703d4a453a72","repo":"ionic-team/ionic-framework","slug":"no-views-in-the-stack-to-be-removed","errorCode":null,"errorMessage":"no views in the stack to be removed","messagePattern":"no views in the stack to be removed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"core/src/components/nav/nav.tsx","lineNumber":641,"sourceCode":"      return false;\n    }\n    this.runTransition(ti);\n    return true;\n  }\n\n  /** Executes all the transition instruction from the queue. */\n  private async runTransition(ti: TransitionInstruction) {\n    try {\n      // set that this nav is actively transitioning\n      this.ionNavWillChange.emit();\n      this.isTransitioning = true;\n      this.prepareTI(ti);\n\n      const leavingView = this.getActiveSync();\n      const enteringView = this.getEnteringView(ti, leavingView);\n\n      if (!leavingView && !enteringView) {\n        throw new Error('no views in the stack to be removed');\n      }\n\n      if (enteringView && enteringView.state === VIEW_STATE_NEW) {\n        await enteringView.init(this.el);\n      }\n      this.postViewInit(enteringView, leavingView, ti);\n\n      // Needs transition?\n      const requiresTransition =\n        (ti.enteringRequiresTransition || ti.leavingRequiresTransition) && enteringView !== leavingView;\n      if (requiresTransition && ti.opts && leavingView) {\n        const isBackDirection = ti.opts.direction === 'back';\n\n        /**\n         * If heading back, use the entering page's animation\n         * unless otherwise specified by the developer.\n         */\n        if (isBackDirection) {","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/ionic-team/ionic-framework/blob/625f9c38ad8c5db8a6c12df5c1622a36da90f9e3/core/src/components/nav/nav.tsx#L623-L659","documentation":"Thrown inside IonNav.runTransition() when, after prepareTI(), there is no leaving view AND no entering view to transition. This means the nav's view stack is empty and the queued transition neither inserts nor resolves to an existing view. The thrown error rejects the transition promise via the surrounding catch → failed() handler.","triggerScenarios":"Calling `pop()`, `popToRoot()`, `popTo(...)`, or `removeIndex(...)` on a nav whose `views` array is empty (no setRoot was ever called), so getActiveSync() returns undefined and getEnteringView() also returns undefined.","commonSituations":"Invoking nav.pop() before any nav.setRoot()/push(); popping a nav whose root was destroyed; race where setRoot has not yet completed before pop is queued; programmatic back button handler firing on a freshly mounted empty nav.","solutions":["Ensure `nav.setRoot(...)` (or at least one `push`) has resolved before calling `pop()`/`popToRoot()`.","Guard the call: check `await nav.getLength() > 0` (or `nav.canGoBack()`) before popping.","Initialize the nav with a root page via the `root`/`rootParams` component property or setRoot on mount.","If popping from a hardware/browser back handler, no-op when the stack is empty instead of calling pop."],"exampleFix":"// before\nconst nav = await this.navRef.getNativeRef();\nawait nav.pop();\n// after\nif (await nav.getLength() > 0) {\n  await nav.pop();\n}","handlingStrategy":"validation","validationCode":"// Before popping, ensure the nav actually has views\nconst length = await nav.getLength();\nif (length === 0) {\n  console.warn('Nav is empty; skipping pop.');\n  return;\n}\nawait nav.pop();","typeGuard":null,"tryCatchPattern":"try {\n  await nav.pop();\n} catch (e) {\n  if ((e as Error).message === 'no views in the stack to be removed') {\n    // nav was empty — initialize a root page instead\n    await nav.setRoot(HomePage);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always set a root page on mount before allowing pop/back actions.","Guard pops with getLength()/canGoBack() in back-button handlers.","Initialize nav with the `root`/`rootParams` props rather than relying on push-after-mount."],"tags":["core","ion-nav","navigation","lifecycle"],"backgroundTag":null,"analyzedSha":"625f9c38ad8c5db8a6c12df5c1622a36da90f9e3","analyzedAt":"2026-08-12T16:00:25.413Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}