Home > widget-integration > FilterStore > initShortenMaps
FilterStore.initShortenMaps() method
Initializes URL parameter shortening maps from the provided configuration.
Creates bidirectional mappings between long and short parameter names for URL optimization. This reduces URL length while maintaining readability in the application code.
Signature:
initShortenMaps(shortenUrlParamList?: string[]): void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
shortenUrlParamList |
string[] |
(Optional) Array of mapping rules in format 'long_key:short_key'. For example, ['productId:pid', 'category:cat']. Invalid formats are silently ignored. Defaults to empty array if not provided. |
Returns:
void
Remarks
The method parses each rule by finding the last ':' character, allowing colons in the long key name. Empty keys are skipped. Both maps are updated atomically via setState() to ensure consistency.
Example 1
Basic usage:
filterStore.initShortenMaps([
'productId:pid',
'categoryName:cat',
'priceRange:pr'
]);
Example 2
Extend to add custom URL shortening rules:
window.boostWidgetIntegration.extend('FilterStore', (FilterStore) => {
return class CustomFilterStore extends FilterStore {
initShortenMaps(shortenUrlParamList = []) {
// Add shop-specific default mappings
const customMappings = [
...shortenUrlParamList,
'shopCustomField:scf'
];
super.initShortenMaps(customMappings);
}
};
});