I am in the process of creating a Next.js application that showcases a product catalog sorted by categories and subcategories. The category and subcategory information is stored in an array of objects structured like this:
const categories = [
{
id: 1,
name: "Category A",
subcategories: [
{
id: 1,
name: "Subcategory A1",
subsubcategories: [
{
id: 1,
name: "Sub-Subcategory A1.1",
},
{
id: 2,
name: "Sub-Subcategory A1.2",
},
],
},
// Other subcategories and sub-subcategories within Category A
],
},
{
id: 2,
name: "Category B",
subcategories: [
// Subcategories and sub-subcategories within Category B
],
},
// Other categories with their respective subcategories and sub-subcategories
];
I aim to create dynamic paths for each product that adhere to the format category/subcategory/subsubcategory/productID. For instance, if a user selects a product with ID 123 in Category A, Subcategory A1, and Sub-Subcategory A1.1, the URL should appear as follows: /category-a/subcategory-a1/sub-subcategory-a1-1/123.
The product details are stored in a separate array of objects shown below:
const products = [
{
id: 123,
name: "Product A1.1.1",
category_id: 1,
subcategory_id: 1,
subsubcategory_id: 1,
description: "Lorem ipsum dolor sit amet",
price: 9.99,
image: "/images/product-a1-1-1.jpg",
},]