Several ways to jump to the uniapp page
1.uni.navigateTo
- Definition: Keep the current page, jump to a page in the application, and use uni.navigateBack to return to the original page.
- use:
// 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
- Definition: You can close the current interface and jump to other non-tabbar interfaces (can take parameters)
- use:
uni.redirectTo({
url:'./home/index'
});
3. uni.reLaunch
- Definition: Close all pages and open to a certain page in the application (can take parameters)
- use:
uni.reLaunch({
url:'./home/index'
});
四、uni.switchTab
- Definition: Jump to the tabBar page and close all other non-tabBar pages
- use:
uni.switchTab({
url:'./home/index'
});
五、uni.navigateBack
- Definition: Close the current page and return to the previous page or multi-level page
- use:
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.