'use strict'; import * as native from 'web/service/native'; import * as urlUtils from 'urlUtils'; import { HistoryOptionString, HistoryOption } from 'base-history'; export function go(url, params?, options?: HistoryOptionString | HistoryOption) { options = filterOptions(options); // 判断是否处于webview环境 const isInWebview = native.isInWebview(); if(isInWebview){ nativeGo(url, params, options); }else{ originGo(url, params, options); } } export function nativeGo(url, params, options) { options = options || {} if(native){ native.history.go(url, params, options); }else{ originGo(url, params, options); } } export function originGo(url, params, options) { const jumpUrl = urlUtils.stringifyUrl(url,params); if(options.replace){ window.location.replace(jumpUrl); }else{ window.location.href = jumpUrl; } } function filterOptions(options) { if(typeof options === 'string'){ switch (options){ case 'replace': return {replace: true}; case 'reload': return {reload: true}; case 'webview': return {webview: true}; case 'back': return {direction: 'back'}; case 'clear': return {clear: true}; case 'origin': return {origin: true}; default: return {}; } }else{ return options || {}; } }