Skip to main content
Use this API to close the current page and open a new page. Unlike my.navigateTo, the current page is removed from the page stack, so users cannot navigate back to it.

Parameters

PropertyTypeRequiredDescription
urlStringYesPage path with optional query parameters (format: path?key=value)
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Code Example

Basic Usage

my.redirectTo({
  url: 'pages/result/result'
});

With Query Parameters

my.redirectTo({
  url: 'pages/result/result?status=success&orderId=12345'
});

With Callbacks

my.redirectTo({
  url: 'pages/home/home',
  success() {
    console.log('Redirected successfully');
  },
  fail(err) {
    console.error('Redirect failed:', err);
  }
});

Use Cases

Page({
  async handleLogin() {
    try {
      await this.login();
      // Replace login page with home - user can't go back to login
      my.redirectTo({
        url: 'pages/home/home'
      });
    } catch (err) {
      my.showToast({ content: 'Login failed', type: 'fail' });
    }
  }
});
// Step pages that shouldn't be revisited
Page({
  completeStep() {
    const nextStep = this.data.currentStep + 1;
    if (nextStep <= 3) {
      my.redirectTo({
        url: `pages/wizard/step${nextStep}`
      });
    } else {
      my.redirectTo({
        url: 'pages/wizard/complete'
      });
    }
  }
});
Page({
  onLoad() {
    if (!this.data.isValid) {
      my.showToast({ content: 'Invalid access', type: 'fail' });
      setTimeout(() => {
        my.redirectTo({ url: 'pages/home/home' });
      }, 1500);
    }
  }
});

Important Notes

  • Cannot redirect to tab bar pages (use my.switchTab instead)
  • The current page is closed and removed from the page stack
  • Users cannot navigate back to the closed page

Differences from Other Navigation APIs

APICurrent PageCan Go Back
my.navigateToKept in stackYes
my.redirectToClosedNo
my.reLaunchAll pages closedNo

my.navigateTo

Navigate keeping current page

my.reLaunch

Close all and open new page