将 javascript 变量添加到 sendgrid 电子邮件中的 url

问题描述

我正在做一个在 node.js 中具有登录注册功能的网站。我正在尝试通过 Sendgrid 在电子邮件中发送新密码链接。我在路由的末尾添加了令牌变量:http://localhost:3000/newPassword/${token} 但是当我单击该链接时,它在我的浏览器中打开为 http://localhost:3000/newPassword/+。因此作为十六进制字符串的令牌值变为加号(+)。这可能是什么原因?当我使用 console.log(token) 打印令牌时,它会打印正确的值。我认为以某种方式错误地解释了 javascript 变量令牌。这是我的代码的 msg 部分:

const msg = {
    to: req.body.email,// Change to your recipient
    from: 'sender@hotmail.com',// Change to your verified sender
    subject: 'Reset your password',html: `  
        <p> Follow this link to reset your password </p>
        <p>
            <a href="http://localhost:3000/newPassword/${token}">
                reset password
            </a>
        </p>`,};
sgMail
    .send(msg)
    .then(()=>{
        console.log('email sent')   
    })
    .catch((err)=>{
        console.log(err)
    })

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)