WeChat applet page jump and data transfer
1. Pilot
In Android, our Activity and Fragment have stacks The concept of stack is in it, and the WeChat applet page also has the concept of stack in it. There are four ways to jump to the WeChat applet page:
1.wx.navigateTo(OBJECT);
2.wx.redirectTo(OBJECT);
3.wx.switchTab( OBJECT);
4.wx.navigateBack(OBJECT)
5. Use to implement the corresponding jump function;
Analysis:
where navigateTo is Save the original page in the page stack. When jumping to the next page, the target page is also pushed into the stack. Only in this case can you click the return button on the phone to jump to the previous page;
RedirectTo and switchTab both clear the original page in the stack first, and then push the target page into the stack. Using these two jump methods, you cannot return to the previous page through the system's return key, but exit directly. Mini program;
When using redirectTo, it must be used with the tabBar or the jump button in the page, otherwise you cannot return to the previous page;
The page that switchTab jumps to must be the page declared in tabBar;
The fields defined in tabBar cannot exceed 5 pages, and the page stack level of the applet cannot exceed 5 layers. .
navigateBack can only return to the specified page in the page stack, and is generally used in conjunction with navigateTo.
wx.navigateTo and wx.redirectTo are not allowed to jump to the tabbar page, only wx.switchTab can be used to jump to the tabbar page
2. Specific operations for page jump
(1)wx.navigateTo(OBJECT)
Keep the current page and jump Go to a page in the application and use wx.navigateBack to return to the original page.
Parameters | Type | Required | Description |
---|---|---|---|
String | is the path of the non-tabBar page in the application that | needs to be jumped to, the path Parameters can be taken later. Parameters and paths are separated by ?, parameter keys and parameter values are connected by =, and different parameters are separated by &; for example, 'path?key=value&key2=value2' | |
Function | No | Callback function for successful interface call | |
Function | No | Callback function for interface call failure | |
Function | No | Callback function for end of interface call Function (executed successfully or failed) |
wx.navigateTo({ url: 'test?id=1'//实际路径要写全 })
//test.js Page({ onLoad: function(option){ console.log(option.query) } })
Note: In order not to cause trouble to users when using the mini program, we stipulate that the page path can only be five levels. Please try to avoid multi-level interactions.
Close the current page and jump to a page within the application.
Type | Required | Description | |
---|---|---|---|
#String | is the non-tabBar page in the app that | needs to jump to Path. Parameters can be taken after the path. Parameters and paths are separated by ?, parameter keys and parameter values are connected by =, and different parameters are separated by &; for example, 'path?key=value&key2=value2' | |
Function | No | Callback function for successful interface call | |
Function | No | Callback function for interface call failure | |
Function | No | Callback function for end of interface call Function (executed successfully or failed) |
wx.redirectTo({ url: 'test?id=1' })
( 3) wx.switchTab(OBJECT)
Jump to the tabBar page and close all other non-tabBar pages
OBJECT parameter description:Required | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
is the path of the tabBar page that | needs to jump to (the page needs to be defined in the tabBar field of app.json), after the path Cannot take parameters | success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No | Callback function for successful interface call | fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No | Callback function for failed interface call | complete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No | The callback function at the end of the interface call (will be executed if the call is successful or failed) | 示例代码: { "tabBar": { "list": [{ "pagePath": "index", "text": "首页" },{ "pagePath": "other", "text": "其他" }] } } Copy after login wx.switchTab({ url: '/index' }) Copy after login (4)wx.navigateBack(OBJECT) 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages()) 获取当前的页面栈,决定需要返回几层。 OBJECT 参数说明:
示例代码: // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码 // 此处是A页面 wx.navigateTo({ url: 'B?id=1' }) Copy after login // 此处是B页面 wx.navigateTo({ url: 'C?id=1' }) Copy after login // 在C页面内 navigateBack,将返回A页面 wx.navigateBack({ delta: 2 }) Copy after login (5)使用 navigator 页面链接。
示例代码: <navigator url="navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator> <navigator url="redirect?title=redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator> <navigator url="index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator> Copy after login 3.页面的路由和生命周期 (1)页面的路由 在小程序中所有页面的路由全部由框架进行管理,对于路由的触发方式以及页面生命周期函数如下:
Tab 切换对应的生命周期(以 A、B 页面为 Tabbar 页面,C 是从 A 页面打开的页面,D 页面是从 C 页面打开的页面为例):
4.参数传递 (1)通过路径传递参数 通过路径传递参数在wx.navigateTo(OBJECT)、wx.redirectTo(OBJECT)和 " wx.navigateTo({ url: 'test?id=1'//实际路径要写全 }) Copy after login //test.js Page({ onLoad: function(option){ console.log(option.id) } }) Copy after login 参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔; test?id=1 中id为参数键,1 为参数值 在目的页面中onLoad()方法中option对象即为参数对象,可以通过参数键来取出参数值 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! 更多微信小程序 页面跳转和数据传递实例详解相关文章请关注PHP中文网!
Related labels:
source:php.cn
Previous article:Detailed explanation of city selector city switching in WeChat applet development
Next article:Detailed explanation of several methods of transferring values in WeChat applet page jumps
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
Latest Articles by Author
Latest Issues
How to display the mobile version of Google Chrome
Hello teacher, how can I change Google Chrome into a mobile version?
From 2024-04-23 00:22:19
0
11
2389
There is no output in the parent window
document.onclick = function(){ window.opener.document.write('I am the output of the child ...
From 2024-04-18 23:52:34
0
1
1890
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|