问题景象:在快利用曾经关上A页面的状况下,此时若从卡片(或其余媒介)跳转至快利用指定页面B,点击左上角返回键,退出页面程序是B-A-卡片,无奈一键间接返回卡片(或其余媒介)。

须要实现的场景:在快利用曾经关上A页面的状况下,从卡片(或其余媒介)跳转至快利用指定页面B,点击左上角返回键可能一键退出快利用,间接返回卡片(或其余媒介)。

问题剖析
上述的问题景象是因为页面采纳了默认的启动模式standard,"standard"模式时会每次关上新的指标页面(屡次关上指标页面地址时会存在多个雷同页面),导致页面栈中会顺次缓存页面A,B,退出时页面会顺次出栈,无奈一键返回。这里倡议用户从卡片跳转至快利用时,应用动静申明的形式指定页面B的启动模式为clearTask即可解决。指定clearTask时,会间接革除原先的页面A,关上页面B,如此页面栈中只有页面B存在,返回时即可间接退出快利用。

解决办法
卡片跳转快利用示例代码(采纳deeplink链接):

<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1.0">  <meta http-equiv="X-UA-Compatible" content="ie=edge">  <title>快利用测试</title></head><body>  <a href="hwfastapp://com.huawei.hello1/Test?___PARAM_LAUNCH_FLAG___=clearTask">应用hwfastapp关上</a>  <br>  <br>  <a href="hap://app/com.huawei.hello1/Test?___PARAM_LAUNCH_FLAG___=clearTask">应用hap关上</a></body></html>

卡片跳转的快利用指标页面(依据以后页面栈的数量能够发现始终只有一个页面):

<template>  <div class="container">    <text>___PARAM_LAUNCH_FLAG___=</text>    <text>{{taskflag}}</text>    <text>以后页面栈的数量</text>    <text>{{length}}</text>  </div></template> <style>  .container {    flex-direction: column;    align-content: center;    align-items: center;    justify-content: center;  }   text {    margin-bottom: 50px;  }</style> <script>import router from '@system.router';  export default {    data: {      // The default is the local app internal image      photoUri: '/Common/logo.png',      taskflag:'',      PARAM_LAUNCH_FLAG:'',      length:''    },     onInit() {      this.$page.setTitleBar({ text: 'deepLink' })      var that=this;      that.taskflag=this.PARAM_LAUNCH_FLAG;      // 调用getPages办法      let pages = router.getPages()      // 因为取得的值是一个JSON数组,所以间接打印是打印不进去的,能够应用上面的办法来打印      console.log("tag", this.printJSONArray(router.getPages()));      that.length= router.getLength();      console.log("pages' length = "+that.length);    },     printJSONArray(array) {      let result = ""      const suffix = ", "      Array.isArray(array) && array.forEach((element, index) => {        result = result + JSON.stringify(element) + (index === array.length-1 ? "" : ", ")        })      return result    }  }</script>

倡议与总结

  1. 页面启动模式有两种配置形式,一种是在manifest文件中动态申明,一种是动静传参申明,倡议应用动静模式,依据本人须要进行配置,动态申明的形式实用于繁多固定场景,无奈灵便调整。

参见文档:

https://developer.huawei.com/...

2.deeplink文档:

https://developer.huawei.com/...

原文链接:https://developer.huawei.com/...
原作者:Mayism