A
A
Andrey Okhotnikov2019-05-24 11:44:43
Node.js
Andrey Okhotnikov, 2019-05-24 11:44:43

Dynamic route in Nextjs?

It is required to implement a dynamic route for displaying products.
Example site.ru/123456?color=5&size=10
Added the following to serverjs

server.get('/:product', (req, res) => app.render(req, res, '/product', {
      params: req.params,
    }));

but in this case the product component will be rendered to any route entered. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-24
@tsepen

1. Change the path to the product: 2. Change the location of the paths:

server.get('/some_route', (req, res) => /* ... */);
server.get('/some_other_route', (req, res) => /* ... */);
server.get('/:product', (req, res) => /* ... */);

Express processes them in a chain, until the first match.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question