使用FETCH从服务器获取页面有什么意义吗?当我看到我的项目中的一些页面导航时,我发现了我的一个小组成员写的这段代码.
fetch("/user/home")
.then((response) => {
if(!response.ok)
throw new Error("Can't go to home.");
location.href = response.url;
})
.catch((error) => console.error("Error:", error));
我们讨论的GET
个人基本上是这样做的:
router.get("/home", (req, res) => {
res.render("userhome");
});
这基本上是在做相同的事情,就好像我输入了以下内容来替换它:
location.href = "/user/home";
如果您可以在1行内完成,那么在6行页面之间导航有什么意义?我是不是明白了一些重要的事情?