我有一个网站,它提供的博客文章的基础上,他们的标题。 但是,当我打开网页时,URL在带有空格的单词之间包含“%20”。 我想这是因为URL编码的原因,但是我想用破折号“-”代替“%20”,这样更容易阅读。
URL示例:
www.example.com/blog/example%20blog%20post
我想把它显示为:
www.example.com/blog/example-blog-post
下面是我的代码:
app.get("/blog-post/:title", getBlogPostController);
module.exports = async (req, res) => {
const articleposts = await ArticlePost.findOne({title: req.params.articletitle});
res.render("blog-post", {
articleposts
});
};
有什么具体的东西我可以改变,使我的URL有破折号而不是百分比符号?
我还将bodyParser URL编码设置为true。 不确定这会不会影响到什么?
您可以使用slug来删除帖子标题,
使用此包使if工作