Home  >  Article  >  Web Front-end  >  How to implement page jump and routing navigation in uniapp

How to implement page jump and routing navigation in uniapp

王林
王林Original
2023-10-27 10:21:521216browse

How to implement page jump and routing navigation in uniapp

How to implement page jump and route navigation in uniapp

In uniapp development, page jump and route navigation are common requirements. This article will introduce how to implement page jumps and routing navigation in uniapp, and provide specific code examples.

1. Page jump

In uniapp, you can use the uni.navigateTo method to jump to the page. This method accepts an object parameter, where url is the page path to jump to, which can be an absolute path or a relative path.

  1. Add the jump code in the trigger event of the jump page. The sample code is as follows:
uni.navigateTo({
  url: '/pages/detail/detail'
})
  1. In the configuration file of the target page, it needs to be in pages Add the corresponding page path to the array. The sample code is as follows:
{
  "pages": [
    "pages/index/index",
    "pages/detail/detail"
  ]
}
  1. In the vue file of the target page, page rendering and data binding can be completed through the components and methods provided by uni-app , the sample code is as follows:
<template>
  <view>
    <text>{{content}}</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      content: '这是详情页面'
    }
  }
}
</script>

2. Route navigation

In uniapp, you can use the uni.switchTab and uni.reLaunch methods for route navigation. Among them, uni.switchTab is used to jump to the tabBar page and close all other non-tabBar pages; uni.reLaunch is used to close all pages and then jump to the specified page.

  1. Use uni.switchTab for routing navigation, the sample code is as follows:
uni.switchTab({
  url: '/pages/index/index'
})
  1. Use uni.reLaunch for routing navigation, the sample code is as follows:
uni.reLaunch({
  url: '/pages/index/index'
})

The above is the basic sample code to implement page jump and route navigation in uniapp. Through the above method, we can easily realize navigation and jump between pages, providing convenient functions for uniapp development. Hope this article is helpful to you.

The above is the detailed content of How to implement page jump and routing navigation in uniapp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn