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

316
Visualizações
How to pass parameters from Pug to Backend JavaScript?

I have this pug page and I need to open the link to a new window. The link is dynamic because it is populated from the backend and when I click the link, I want to open it in a new tab.

How do I do it ?

layout.pug

a(href='/goto/?url='+url)

main.js

app.get('/goto/?url=:url', (req, res) => {
    var new_tab_url = req.params.url;
    window.open(new_tab_url, '_blank').focus();
});

I need to pass the URL from layout.pug to main.js to open a new tab. But I keep getting error

Cannot GET /goto/

Or perhaps , is there other simpler way ? Thank you

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

To open a link in a new window, just use this:

a(href= url, target='_blank')

There's no reason to pass a variable to a backend router or try to handle the redirection server-side. Just use target="_blank".

about 4 years ago · Juan Pablo Isaza Relatório

0

My bad. This topic is closed since the issue has been resolved.

I am using Express (Node.JS) and this is what I do :

layout.pug

a(href='/goto/?url='+url)

main.js

app.get('/goto', (req, res) => {
    var new_tab_url = req.query.url;
    res.redirect(new_tab_url);
});

At least this works on my issue.

Using : NodeJS Express and Pug

about 4 years ago · Juan Pablo Isaza 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