Week navigator.push jumps to display the contents of the js file
write a page jump in week navigator.push. The demo, jump in the past is the corresponding js displayed.
jump(){
console.log(213)
this.baseURL = "http:/dist/components/detail.js"
var params = {
"url": this.baseURL,
"animated" : "true",
}
navigator.push(params,function(){
});
}
is there any god who can explain why
there is something wrong with your baseUrl. Here is what we do for your reference:
Public methods in
common.js:
exports.bundleUrl = function (self) {
var bundleUrl = self.$getConfig().bundleUrl;
return bundleUrl;
};
/ / judging the system, Android returns' android',ios returns' iOS',h5 returns' web'
exports.androidOrIos = function (self) {
return self.$getConfig().env.platform;
};
/ / get the url address
exports.getBaseUrl = function (self) {
var androidOrIos = this.androidOrIos(self);
var bundleUrl = this.bundleUrl(self);
var isHttp = bundleUrl.indexOf('http://') >= 0;
var nativeBase;
if (isHttp) {
var i = bundleUrl.indexOf('/dist/');
nativeBase = bundleUrl.slice(0, i) + '/dist/';
} else {
if (androidOrIos == 'android') {
nativeBase = 'file://assets/dist/';
} else if (androidOrIos == 'iOS') {
nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('dist/') + 5);
} else {
var host = 'localhost:12580';
var matches = /\/\/([^\/]+?)\//.exec(bundleUrl);
if (matches && matches.length >= 2) {
host = matches[1];
}
nativeBase = 'http://' + host + '/example/build/';
}
}
var h5Base = './index.html?page=./example/build/';
// in Native
var base = nativeBase;
if (typeof window === 'object') {
base = h5Base;
}
return base;
};
/ / Jump to the specified url page
/ *
* url request address. The prefix has been added. Pass values for baseUrl, such as: 'login/login';
* param is required parameter, pass values such as:' name1=value1&name2=value2'
* callback'is callback function, pass values such as: function () {};
* /
exports.jump = function (self, url, param, callback) {
var navigator = weex.requireModule('navigator');
var baseUrl = this.getBaseUrl(self);
var param = param ? param : '';
var url = {'url': baseUrl + url + '.js?' + param, 'animated': 'true'};
navigator.push(url, function (e) {
if (callback) {
typeof callback == 'function' && callback(res);
}
});
}
call on the page:
import common from'. / common/common';
export default {
methods: {
toTest() {
common.jump(this, 'test/test');
}
}
}