title: Taro.navigateTo(option)

sidebar_label: navigateTo

Keeps the current page open and redirects to a page (except for the tabbar page) in the app. You can return to the original page using Taro.navigateBack. The page stack in the WeChat Mini-Program is limited to ten layers.

Reference

Type

  1. (option: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
url string Yes Path to a non-tabBar page to be navigated to in the app. Parameters can be appended after the path. You can use ? to separate the path from parameters, = to connect a parameter key with a parameter value, and & to separate different parameters. For example, ‘path?key=value&key2=value2’.
complete (res: CallbackResult) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
events Record<string, any> No Inter-page communication interface for listening to data sent to the current page by the opened page.
fail (res: CallbackResult) => void No The callback function for a failed API call
success (res: CallbackResult) => void No The callback function for a successful API call

Sample Code

  1. Taro.navigateTo({
  2. url: 'test?id=1',
  3. events: {
  4. acceptDataFromOpenedPage: function(data) {
  5. console.log(data)
  6. },
  7. someEvent: function(data) {
  8. console.log(data)
  9. }
  10. ...
  11. },
  12. success: function (res) {
  13. res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
  14. }
  15. })

API Support

API WeChat Mini-Program H5 React Native
Taro.navigateTo ✔️ ✔️ ✔️