兼容三端
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" });