Home > Web Front-end > uni-app > body text

How to implement page jump and routing navigation in uniapp

王林
Release: 2023-10-27 10:21:52
Original
1234 people have browsed it

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'
})
Copy after login
  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"
  ]
}
Copy after login
  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>
Copy after login

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'
})
Copy after login
  1. Use uni.reLaunch for routing navigation, the sample code is as follows:
uni.reLaunch({
  url: '/pages/index/index'
})
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!