简体   繁体   English

用不同的 id 表示 js 路由

[英]Express js route with different ids

Im using node js with express lib.There are pages like localhost/page/1,localhost/page/2.我使用带有 express lib 的节点 js。有像 localhost/page/1、localhost/page/2 这样的页面。 They are pretty similar but some information must change depending on page id.它们非常相似,但某些信息必须根据页面 ID 进行更改。 Im redirecting to this pages with form submit.我使用表单提交重定向到此页面。

<form method='GET' action='/order_page/" + order.id[i] + "'><input type='submit' value='move'></form>

and in my server js在我的服务器 js 中

app.get('order_page/:id', checkUserSession, function(request, response) {
    response.send(req.id);
});

it redirects and gives me error Cannot GET /order_page/6它重定向并给我错误无法获取 /order_page/6

What's the best solution to this issue?这个问题的最佳解决方案是什么?

You are missing / before the order_page :您在 order_page 之前缺少/

app.get('/order_page/:id', checkUserSession, function(request, response) {
    response.send(req.id);
});

I think you should add a "/" before "order_page/:id"我认为你应该在“order_page/:id”之前添加一个“/”

app.get('/order_page/:id', checkUserSession, function(request, response) {
response.send(req.id);});

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

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