I use Next.js on my project and I need to make a dynamic query string. I use this code:
const createQuery = (filter) => {
let currentPath = router.pathname;
let filterSize = Object.keys(filter).length;
filterSize != 0 ? (currentPath += "?") : null;
Object.keys(filter).map(function (key, index) {
currentPath +=
key + "=" + filter[key] + (index === filterSize - 1 ? "" : "&");
});
router.push(currentPath);
};
It works but I don't send an array to query string. How can I do this? Also, ss there an easier way to create a query string in Next.js?