Node Pug:使用变量时表单标签的动作属性无法正常工作

发布时间:2021-02-25 08:02

我有一个 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?

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

我附上了截图以供参考。

enter image description here

回答1

试试

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