mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
✨ Allow replacing query args via navigation util
Before, we could only add or modify items. This change allows us to _remove_ query arguments from the URL
This commit is contained in:
parent
3e5e997f04
commit
23045aa77a
1 changed files with 7 additions and 4 deletions
|
@ -22,11 +22,14 @@ export const getQuery = () =>
|
|||
/**
|
||||
* Updates the query parameters of the current page.
|
||||
*
|
||||
* @param {Object} query Object of params to be updated.
|
||||
* @param {Object} query Object of params to be updated.
|
||||
* @param {boolean} [replace=false] Whether to add the query vars (false) or replace previous query vars with the new details (true).
|
||||
* @throws {TypeError} If the query is not an object.
|
||||
*/
|
||||
export const updateQueryString = ( query ) =>
|
||||
pushHistory( getNewPath( query ) );
|
||||
export const updateQueryString = ( query, replace = false ) => {
|
||||
const newQuery = replace ? query : { ...getQuery(), ...query };
|
||||
return pushHistory( getNewPath( newQuery ) );
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a URL with set query parameters.
|
||||
|
@ -36,4 +39,4 @@ export const updateQueryString = ( query ) =>
|
|||
* @return {string} Updated URL merging query params into existing params.
|
||||
*/
|
||||
export const getNewPath = ( query, basePath = getPath() ) =>
|
||||
addQueryArgs( basePath, { ...getQuery(), ...query } );
|
||||
addQueryArgs( basePath, query );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue