快速路由 url 操作中的问题

问题描述 投票:0回答:1

需要快速路由帮助 当用户转到 /page2 时,它应该只看到 localhost:3000/page2 而不是显示 localhost:3000/page2.html

我有 3 个 html 页面,其中包含一些数据。假设 page1.html、page2.html 和 page3.html。我使用express创建了一个服务器并创建了这样的路由

App.get(“/page2” ,(req,res)=>{ Res.sendFile(path.join(__dirname,’public’,”page2.html));

}); 当我点击

<a href=“/page2”>Go to page 2.</a>
时 它正在打开 page2.html 但同时 url 也更改为 localhost:3000/page2.html 我不希望我的用户看到 url 中的 html 文件 相反,我只想显示 localhost:3000/page2 我怎样才能做到这一点?你们有什么想法吗?

javascript html express routes path
1个回答
0
投票

尝试对 MVC Nodejs 使用 .ejs 文件。

https://github.com/Elnur21/smart-edu/tree/main/smart-edu

© www.soinside.com 2019 - 2024. All rights reserved.