Options
All
  • Public
  • Public/Protected
  • All
Menu

Module url/replaceUrlParams

Index

Functions

Functions

replaceUrlParams

0.0.35 provide
  • replaceUrlParams(newParams: Record<string, any>, options?: ReplaceParamsOptions): string
  • 替换当前URL上的参数并生成新的链接

    remarks

    如果当前URL上不存在传入的参数,也会直接添加到新生成的URL后 替换当前location.href上的参数,生成新的链接

    remarks

    针对带有hash的链接,需要遵循先search参数,后hash参数的原则

    example

    normal

    import { url } from 'onex-utils';
    const { replaceUrlParams } = url;
    replaceUrlParams({ a: 1 });
    
    example

    assign url option

    import { url } from 'onex-utils';
    
    const { replaceUrlParams } = url;
    replaceUrlParams({node: 'test'}, { url: 'https://taobao.com/pribuy#/firstbuy/list?node=1' });
    

    Parameters

    • newParams: Record<string, any>

      需要替换的URL新参数,如果原链接中存在将会进行覆盖

    • Optional options: ReplaceParamsOptions

      自定义配置参数

    Returns string

    with query prefix url