尽管已声明路由,快速路由仍返回 404
因此,在我的后端服务器上,我声明了一个接受参数的路由,
这就是路由:
router.route('/freeze-check/:region').get(freezeCheck);
freezeCheck 只是一个从数据库中提取数据的控制器,该数据库会过滤掉带有 RegionId 的产品。
在我的前端,我通过这样做来调用这条路由:
const adminRegion = props.authData.admin.region.id;
const res = await apiCaller.get(`/products/freeze-check`, { params: { region: adminRegion }
apiCaller 只是带有一些设置的 axios 导出。我多次控制台记录 adminRegion 并返回预期值,这是从 redux 存储中提取的状态,但是后端返回以下内容:
GET /api/products/freeze-check?region=1 404 30.114 ms - 164
自从我在后端声明该路由以来,我没有得到任何基本 URL,所有基本 URL 都工作正常我可以验证这一点,我是否缺少语法或其他东西?这是因为旧的express或axios版本吗?
我正在使用:
express:^4.14.0
axios:^0.16.2
So on my backend server, I have declared a route that accepts params
This is the route:
router.route('/freeze-check/:region').get(freezeCheck);
freezeCheck is just a controller that pulls from the db that filters out products with the regionId.
On my front end I called this route by doing this:
const adminRegion = props.authData.admin.region.id;
const res = await apiCaller.get(`/products/freeze-check`, { params: { region: adminRegion }
apiCaller is just axios exported with some settings. I console logged adminRegion multiple times and it returns the expected value, this is a state pulled from redux store however the backend returns with this:
GET /api/products/freeze-check?region=1 404 30.114 ms - 164
Which I don't get since I declared that route in the backend all the base URLS are working fine I can verify this, am I missing a syntax or something? is this because of the old express or axios version?
I'm using:
express: ^4.14.0
axios: ^0.16.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过查看您的请求响应,您不会将该区域作为参数发送,而是作为查询发送。
尝试发送这样的参数,
如果参数是可选的,你可以像这样发送。在路由中传递尾随问号,
其余代码应该保持原样。
By looking at your request response,you're not sending the region as params instead as a query.
Try to send the param like this
if the params is optional you could to something like this. pass an trailing question mark in a route
the remaining code should be as it should be.