Physical return key event handling

Physical return key

1) In app:
On app1, H5 and app agree to define a global method on the window object, such as the window.back method. H5 will define the method at the route definition position. When the physical return key is triggered, the app will listen to the method back defined by both parties, and if the method is defined, the method will be executed

2) In non-app environments, such as browsers, WeChat and other environments, when using the popstate method to monitor the 
processing here, you need to distinguish whether it is triggered by routing or physical. The routing triggers the popostate() method, and the physical event processing is not performed (due to the router The .replace() and router.push() methods will also trigger the popstate() method), so an identifier is needed to indicate that it is the popstate method triggered by the route. If the route is triggered, the method that handles the return of the physical key is not called, and the physical key is triggered. The popstate method before calling the physical key return method

3) SDK access to the app is
also the corresponding method agreed by both H5 and app


The method of the physical return key of app1:
window.back (applicable to ios android) Return value description:
return 0: close the current web view
return 1: return to the previous page normally
return 2: do nothing

Plug-in form, the method of E-Enterprise physical return key:
window.onBackForward (applicable to android. iOS) Return value description:
return 0: do nothing
return 1: return to the previous page normally

 

The router object is defined in router/index.js, and the information that can be obtained through the object
let history = router.history
history = {    base:'',    current: {}, — current routing object    cb: fn,    errorCbs: [],    router: {} }





Information of the current route object:
current = {      fullPath:'/home',      name:'home',      path:'/home'      hash:'',      matched: [],      meta: {}. // Defined in the route Field      params: {}, // Custom attributes before route jump      query: {} // Custom attributes before route jump } The useful information is the params in current. The custom attributes in query









The fields of to and from objects in current and beforeRouteEnter(to, from, next) are the same

Guess you like

Origin blog.csdn.net/tangxiujiang/article/details/109697460