M
M
mrrangerr2020-07-10 19:38:19
Node.js
mrrangerr, 2020-07-10 19:38:19

How to generate routes based on data from mysql?

Good evening everyone, on the main route I render a list of products, how to generate a unique route for each product?

Here is my code

app.get('/', (req, res) => {
    Products.findAll({
        raw: true
    })
        .then(products => {
            res.render('index.hbs', {
                products: products
            })
        })
        .catch(err => console.log(err));
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynatik001, 2020-07-10
@Lynatik001

Well, if you hit the question in the title. then a unique route can be created from the product ID. + there are categories or something else, so that the unique ID does not intersect if there is another table with products too. Or you can generate 20 characters from random typing there, and write them together with the product, under the route field. (When adding a new product)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question