router.js
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Promise from '../vendors/es6-promise';
import wx from '../utils/wx';
import {parse, stringify} from '../vendors/query-stringify';
import gominiapp from './gominiapp';
// 跳转到小程序内
// router.go('https://miniapp.yohobuy.com/pages/index/index?xxxx=ghh&ytty=444');
// 跳转到小程序外
// router.go('https://miniapp.yohobuy.com/pages/index/index?app=yohobuy&xxxx=ghh&ytty=444');
const miniAppDomain = 'miniapp.yohobuy.com';
export default {
go(url = '') {
if (!url) {
return Promise.reject('error url');
}
const [uri, search] = url.split('?');
const path = uri.split(miniAppDomain)[1];
const qs = parse(search);
if (!path) {
return Promise.reject('error path');
}
if (qs.app) {
return gominiapp({
app: qs.app,
path: `${path}?${stringify(qs)}`
});
} else {
return wx.navigateTo({
url: `${path}?${stringify(qs)}`
});
}
}
};