weex:怎么实现页面跳转兼容三端

  • 只在H5中使用
<script>
....
const navigator = weex.requireModule("navigator");
</script>
 navigator.push({
        url: "./detail.html",
        animated: "true"
      });

这样就可以在H5中进行跳转

  • 兼容三端

1、在src根目录下创建utils

export function getEntryUrl(name) {
    // 判断当前的环境,适配web端
    if (weex.config.env.platform === "Web") {
        return './' + name + '.html'
    } else {
        let arr = weex.config.bundleUrl.split('/');
        arr.pop();
        arr.push(name + '.js');
        return arr.join('/');
    }
}

2、引入utils

<script>
....
const navigator = weex.requireModule("navigator");
import { getEntryUrl } from "./utils";
</script>

3、实现跳转

navigator.push({
        // url: "./detail.html",
        url: getEntryUrl("detail"),
        animated: "true"
      });
  • 返回页面
navigator.pop({
              animated: "true"
            });

猜你喜欢

转载自blog.csdn.net/huangxiaoguo1/article/details/80326274