Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
How can I create search result page on example.com/s/keyword?

app.js

app.get('/results',showResult)
var express = require('express')
var n = req.query.query;
mysql_crawl.query('SELECT prod_name, full_price FROM `xxx` WHERE MATCH(data_index) AGAINST("'+n+'")', function(error, product_data) {
res.render('result.html', {result: n, related: product_data: product_data})
        });

result.html

<form action= '/results' class="input-group input-group-lg" id="search">
         <input type="text" class="input-group form-control"  name="query" value='<%= result %>'/>
               <span class="input-group-btn">
                     <button class="btn btn-secondary" type='button'>Search</button>
               </span>
</form>

When I search, I get a URL like example.com/results?query=keyword, but I want a results page at example.com/s/keyword.

Both pages should be the same results. If I change the keyword in the URL, it should show search results for that keyword.

So my question is, how do I create the example.com/s/keyword page to duplicate the results at example.com/results?query=keyword?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

app.get('/s/price/:sea_query', function (req, res) {
    var n = req.params.sea_query;
};

I can use this to get data from url, thanks :)

about 4 years ago · Santiago Trujillo Relatório

0

You can create new route as

app.get('/s/:keyword', function (req, res) {
    var n = req.params.keyword;
    // do rest of the task
};

Instead of repeating same code in two route, you can create a function then call the same function in both routes.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda