设置此类路由的处理:
app.get('/users/:username', (req, res) => {
let username = req.params.username;
// ...
});
如果昵称username不包含任何特殊字符,则一切正常。也就是说,当通过引用传递时,正确的值会被写入http://localhost/users/Don2Quixote到变量中。username如果昵称看起来像这样:new_user#0003,那么“#0003”部分将被丢弃,username只有new_user.
此外,如果您使用req.originalUrl,输出将是/users/new_user:我敢假设,有必要使用 URL Encode 吗?
该怎么办?
octothorpe(字符
#)之后的任何内容都不会发送到服务器(在GET请求的情况下)。window.location.hash如果我们谈论的是 js,它只能在客户端通过.如果您的变量包含类似的特殊字符,则使用类似 thread 的内容进行编码
encodeURIComponent()。或者通过他们不通过
query。