简体   繁体   English

快速获取请求

[英]Express get requests

I am making a site with angular 4, express and mongo. 我正在制作一个包含4号角,express和mongo的网站。 It is my first site and I am not really sure how to use get requests. 这是我的第一个站点,我不确定如何使用get请求。 I know that they are for requesting data from the server. 我知道它们是用于从服务器请求数据。 So i used them for my request to the database. 因此,我将它们用于我对数据库的请求。 The problem with that is if the user is on the localhost:3000/games/1 if he refreshes the page he does not recieve the site. 问题在于,如果用户刷新了自己未接收到该页面的页面,则该用户位于localhost:3000/games/1上。 Instead he recieves only the info from the database. 相反,他仅从数据库中接收信息。 How do i fix this? 我该如何解决? Any help would be appreaciated. 任何帮助将不胜感激。

this.Router
  .get("/games/:id", (req, res) => this.controller.getAll(req, res))
  .get("/*", this.controller.getSite);

Above is an expmple of my problem if i am on games/:id and i refresh i only get the db info and not the webpage 上面是我的游戏问题,如果我在游戏/:id上并且刷新,我只会得到数据库信息而不是网页

始终保持API和视图的URL不同,例如,如果用户访问example.com/games/1来查看网页,而访问API来获取数据的API则不一样,则应使它类似于example.com/api/games/1可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM