Home Web Front-end uni-app Design and development practice of UniApp to implement route management and page jump

Design and development practice of UniApp to implement route management and page jump

Jul 04, 2023 pm 07:51 PM
uniapp design development practices Page jump Route management

UniApp is a cross-platform application development framework based on Vue.js, which can be written once and run on multiple terminals. In UniApp, implementing routing management and page jumps is a very common requirement. This article will discuss the design and development practices of routing management and page jumps in UniApp, and give corresponding code examples.

1. UniApp routing management

In UniApp, routing management mainly includes two aspects: routing configuration and routing jump. Below we will introduce these two aspects respectively.

  1. Routing configuration

The routing configuration of UniApp is mainly performed in the pages.json file of the project. In the pages.json file, you can configure the page path, page name, page style and other information. An example is as follows:

{
  "pages": [
    {
      "path": "pages/home/home",
      "name": "home",
      "style": {
        "navigationBarTitleText": "首页"
      }
    },
    {
      "path": "pages/login/login",
      "name": "login",
      "style": {
        "navigationBarTitleText": "登录"
      }
    }
  ]
}
Copy after login

In the above example, we have defined two pages: home and login. The path field represents the path of the page, the name field represents the page name, and the style field represents the page style. Can be configured according to actual needs.

  1. Route jump

Route jump in UniApp is implemented through the uni.navigateTo or uni.redirectTo method. The uni.navigateTo method is to retain the current page, jump to a page within the application, and return to the previous page through uni.navigateBack. uni.redirectToThe method is to close the current page and jump to a page within the application. The example is as follows:

// 在某个页面的点击事件中跳转到home页面
uni.navigateTo({
  url: '/pages/home/home'
});

// 在某个页面的点击事件中跳转到login页面
uni.redirectTo({
  url: '/pages/login/login'
});
Copy after login

In the above example, routing can be implemented by calling the uni.navigateTo or uni.redirectTo method and passing in the path of the target page. Jump. Different methods can be used in different situations as needed.

2. Design and development practice of UniApp page jump

In actual development, we may need to jump from one page to another and pass some parameters. Below we will introduce how to implement page jump with parameters in UniApp.

  1. Page parameter passing

In UniApp, page parameter passing can be done through uni.navigateTo or uni.redirectTo This is achieved by passing parameter objects in the method. An example is as follows:

// 在某个页面的点击事件中跳转到另一个页面,并传递参数
uni.navigateTo({
  url: '/pages/detail/detail?id=1&name=test'
});
Copy after login

In the above example, parameters can be passed by adding parameters to the URL parameters of the target page. In the target page, the passed parameters can be obtained through the uni.getLaunchOptionsSync().query method. An example is as follows:

export default {
  onLoad(query) {
    console.log(query.id); // 输出1
    console.log(query.name); // 输出test
  }
}
Copy after login

In the onLoad life cycle function of the target page, the passed parameters can be obtained through the query parameter.

  1. Page receiving parameters

In some cases, it may be necessary to achieve communication between pages through page jumps. For example, jump from the login page to the home page and display user information on the home page. Below we will introduce how to implement page communication in UniApp.

First, define a global variable in the login page to store user information. An example is as follows:

// 登录成功后保存用户信息
uni.setStorageSync('userInfo', {
  id: 1,
  name: 'test'
});
Copy after login

Then, obtain user information through the uni.getStorageSync method on the homepage. An example is as follows:

export default {
  data() {
    return {
      userInfo: {}
    };
  },
  onLoad() {
    // 获取用户信息
    this.userInfo = uni.getStorageSync('userInfo');
  }
}
Copy after login

In the above example, the stored user information is obtained by calling the uni.getStorageSync method, and then assigned to the userInfo variable. When the page loads, user information can be obtained and related operations can be performed.

Summary:

Through the introduction of this article, we have learned about the design and development practices of routing management and page jumps in UniApp. Route configuration and route jump can be completed in the pages.json file and the uni.navigateTo or uni.redirectTo method. Communication between pages can be achieved by passing parameters during page jumps. I hope the content of this article will be helpful to everyone in routing management and page jumps in UniApp development.

The above is the detailed content of Design and development practice of UniApp to implement route management and page jump. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Apr 17, 2024 pm 06:50 PM

According to news on April 17, HMD teamed up with the well-known beer brand Heineken and the creative company Bodega to launch a unique flip phone - The Boring Phone. This phone is not only full of innovation in design, but also returns to nature in terms of functionality, aiming to lead people back to real interpersonal interactions and enjoy the pure time of drinking with friends. Boring mobile phone adopts a unique transparent flip design, showing a simple yet elegant aesthetic. It is equipped with a 2.8-inch QVGA display inside and a 1.77-inch display outside, providing users with a basic visual interaction experience. In terms of photography, although it is only equipped with a 30-megapixel camera, it is enough to handle simple daily tasks.

ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps Apr 26, 2024 pm 03:46 PM

According to news on April 26, ZTE’s 5G portable Wi-Fi U50S is now officially on sale, starting at 899 yuan. In terms of appearance design, ZTE U50S Portable Wi-Fi is simple and stylish, easy to hold and pack. Its size is 159/73/18mm and is easy to carry, allowing you to enjoy 5G high-speed network anytime and anywhere, achieving an unimpeded mobile office and entertainment experience. ZTE 5G portable Wi-Fi U50S supports the advanced Wi-Fi 6 protocol with a peak rate of up to 1800Mbps. It relies on the Snapdragon X55 high-performance 5G platform to provide users with an extremely fast network experience. Not only does it support the 5G dual-mode SA+NSA network environment and Sub-6GHz frequency band, the measured network speed can even reach an astonishing 500Mbps, which is easily satisfactory.

How to start preview of uniapp project developed by webstorm How to start preview of uniapp project developed by webstorm Apr 08, 2024 pm 06:42 PM

Steps to launch UniApp project preview in WebStorm: Install UniApp Development Tools plugin Connect to device settings WebSocket launch preview

Which one is better, uniapp or mui? Which one is better, uniapp or mui? Apr 06, 2024 am 05:18 AM

Generally speaking, uni-app is better when complex native functions are needed; MUI is better when simple or highly customized interfaces are needed. In addition, uni-app has: 1. Vue.js/JavaScript support; 2. Rich native components/API; 3. Good ecosystem. The disadvantages are: 1. Performance issues; 2. Difficulty in customizing the interface. MUI has: 1. Material Design support; 2. High flexibility; 3. Extensive component/theme library. The disadvantages are: 1. CSS dependency; 2. Does not provide native components; 3. Small ecosystem.

Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Jul 18, 2024 am 09:27 AM

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of ​​​​sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

Teclast M50 Mini tablet is here: 8.7-inch IPS screen, 5000mAh battery Teclast M50 Mini tablet is here: 8.7-inch IPS screen, 5000mAh battery Apr 04, 2024 am 08:31 AM

According to news on April 3, Taipower’s upcoming M50 Mini tablet computer is a device with rich functions and powerful performance. This new 8-inch small tablet is equipped with an 8.7-inch IPS screen, providing users with an excellent visual experience. Its metal body design is not only beautiful but also enhances the durability of the device. In terms of performance, the M50Mini is equipped with the Unisoc T606 eight-core processor, which has two A75 cores and six A55 cores, ensuring a smooth and efficient running experience. At the same time, the tablet is also equipped with a 6GB+128GB storage solution and supports 8GB memory expansion, which meets users’ needs for storage and multi-tasking. In terms of battery life, M50Mini is equipped with a 5000mAh battery and supports Ty

How to design the end page of ppt to be attractive enough How to design the end page of ppt to be attractive enough Mar 20, 2024 pm 12:30 PM

At work, ppt is an office software often used by professionals. A complete ppt must have a good ending page. Different professional requirements give different ppt production characteristics. Regarding the production of the end page, how can we design it more attractively? Let’s take a look at how to design the end page of ppt! The design of the ppt end page can be adjusted in terms of text and animation, and you can choose a simple or dazzling style according to your needs. Next, we will focus on how to use innovative expression methods to create a ppt end page that meets the requirements. So let’s start today’s tutorial. 1. For the production of the end page, any text in the picture can be used. The important thing about the end page is that it means that my presentation is over. 2. In addition to these words,

What development tools do uniapp use? What development tools do uniapp use? Apr 06, 2024 am 04:27 AM

UniApp uses HBuilder

See all articles