Skip to main content
Use this API to close the current page and return to a previous page in the page stack.

Parameters

PropertyTypeRequiredDescription
deltaNumberNoNumber of pages to go back. Default: 1

Code Example

Go Back One Page

my.navigateBack();

Go Back Multiple Pages

// Go back 2 pages
my.navigateBack({
  delta: 2
});

With Validation

Page({
  goBack() {
    const pages = getCurrentPages();
    if (pages.length > 1) {
      my.navigateBack();
    } else {
      // Already at first page, go to home
      my.switchTab({
        url: 'pages/home/home'
      });
    }
  }
});

Use Cases

<!-- AXML -->
<view class="header">
  <view class="back-btn" onTap="goBack">
    <text>Back</text>
  </view>
  <text class="title">Detail</text>
</view>
Page({
  goBack() {
    my.navigateBack();
  }
});
Page({
  async submitForm() {
    try {
      await this.saveData();
      my.showToast({
        content: 'Saved successfully',
        type: 'success'
      });

      // Return to previous page after delay
      setTimeout(() => {
        my.navigateBack();
      }, 1500);
    } catch (err) {
      my.showToast({
        content: 'Save failed',
        type: 'fail'
      });
    }
  }
});
// If page stack is: Home > List > Detail > Edit
// Go directly back to List (skip Detail)
Page({
  onSaveAndReturn() {
    my.navigateBack({
      delta: 2
    });
  }
});

Notes

  • If delta is greater than the number of pages in the stack, it navigates to the first page
  • You cannot navigate back from the first page in the stack
  • Use getCurrentPages() to check the current page stack

my.navigateTo

Navigate to a new page

my.reLaunch

Relaunch to a page