首页 > 解决方案 > Node Pug:使用变量时表单标签的动作属性无法正常工作

问题描述

我有一个 index.pug 页面,它是:

    head
        title My Title
    body
        form(method="GET", action='/#{redirect_url}')
            button(type='submit') run foo

在我的 app.js 中,我有:

app.get('/', (req, res) => {
    res.render('index', {
        redirect_url: '/foo'
    });
});

app.get('/foo', (req, res) => {
    res.status(200).send('Foo triggered');
});

我被重定向到 http://localhost:3000/?#{redirect_url}。

我想重定向到 http://localhost:3000/redirect_url?

当我不使用变量时它工作正常。

我附上了截图供参考。

在此处输入图像描述

标签: node.jsexpresspug

解决方案


尝试

action=`${baseRoute}/${redirect_url}`

推荐阅读