@unbxd-ui/unbxd-search-core
v0.5.11
Published
Search JS Core Library
Downloads
511
Keywords
Readme
search-JS-core
Core library for Search JS
Getting started
this library is the dependancy for search-JS-library and react-search-JS-SDK, provides the api for interacting with search api.
Prerequisites
Install npm
Setting Up
- use node 14.15.0
Install the npm packages & start the dev server using following commands
npm install
npm run start
ES6
Install @unbxd-ui/unbxd-search-core
using npm.
npm install @unbxd-ui/unbxd-search-core --save
Import the UnbxdSearchCore function in your project
import UnbxdSearchCore from "@unbxd-ui/unbxd-search-core";
if(redirect) {
const {
value,
type
} = redirect;
if(type === "url") {
/** If opening in same tab */
if(history.state && history.state.replace) {
history.replaceState(null,"",urlBeforeRedirect);
}
location.href = value;
/** If opening redirect in new tab (rare scenario),
* then browser back + history push on search should be handled by client
* (especially switching betsween category to search page scenarios)
* Note: This is not recommended */
}
return false;
}
},
onBackFromRedirect: (hashMode) => {
let urlSearchParam = new URLSearchParams(hashMode ? location.hash.substring(1) : location.search);
let backFromRedirect = urlSearchParam.get("redirected");
if(backFromRedirect) {
history.go(-1);
}
},
onNoUnbxdKeyRouting:() => {
history.go();
},
setRoutingStrategies:(locationParam, newUrl, productType, isUnbxdKey, replace) => {
if (locationParam === newUrl) {
return;
} else if (productType === "CATEGORY") {
/** Do not navigate to base category page */
if (!isUnbxdKey) {
history.replaceState(null, "", newUrl);
} else {
history.pushState(null, "", newUrl);
}
} else {
if ((history.state && history.state.replace) || replace) {
history.replaceState(null, "", newUrl);
} else {
history.pushState(null, "", newUrl);
}
}
}
});
SDK Apis
The available apis are listed here.