Several ways to jump to the uniapp page

Several ways to jump to the uniapp page


1.uni.navigateTo

  1. Definition: Keep the current page, jump to a page in the application, and use uni.navigateBack to return to the original page.
  2. use:
    Insert image description here
// 1.不传参
uni.navigateTo({
    
    
    url:'./home/index'
});
// 2.传参字符串
uni.navigateTo({
    
    
    url:`./home/index?title=${
    
    title}`
});
// 3.传参对象
// 传入
let data = {
    
    
    title:'hello',
    id: 1
}
uni.navigateTo({
    
    
	url:`./home/index?data=`+ encodeURIComponent(JSON.stringify(data))
})

// 接受参数
onLoad: function (option) {
    
    
    const item = JSON.parse(decodeURIComponent(option.item));
}

Second, uni.redirectTo

  1. Definition: You can close the current interface and jump to other non-tabbar interfaces (can take parameters)
  2. use:
    Insert image description here
uni.redirectTo({
    
    
  url:'./home/index'
});

3. uni.reLaunch

  1. Definition: Close all pages and open to a certain page in the application (can take parameters)
  2. use:
    Insert image description here
uni.reLaunch({
    
    
    url:'./home/index'
});

四、uni.switchTab

  1. Definition: Jump to the tabBar page and close all other non-tabBar pages
  2. use:
    Insert image description here
uni.switchTab({
    
    
   url:'./home/index'
});

五、uni.navigateBack

  1. Definition: Close the current page and return to the previous page or multi-level page
  2. use:
    Insert image description here
uni.navigateBack({
    
    
    url:'./home/index'
});
uni.navigateBack({
    
    
	delta: 2
});

总结

navigateTo and redirectTo can only open non-Tab pages and can pass parameters.
switchTab can only open the Tab page and cannot pass parameters.
reLaunch can open any page and pass parameters.

Guess you like

Origin blog.csdn.net/m0_56144469/article/details/128559006