替换相应url参数的值

256 阅读1分钟

import queryString from 'querystring';(插件 npm install querystring)

export function replaceState(data) {

if (data && window.history && window.history.replaceState) {
    const parsed = queryString.parse(window.location.search.replace('?', ''));
    Object.assign(parsed, data);
    console.log(queryString, parsed, window.location.search, 66666);
    const url = window.location.origin + window.location.pathname + '?' + queryString.stringify(parsed);
    console.log(url);
    window.history.replaceState(null, window.document.title, url);
}

}

问题:修复浏览任务开红包返回异常

修复:首页接口请求成功之后,把shareId 置 ''

if(GetQueryString('name')){ replaceState({'name':''}); }