【问题标题】:Node Express path hash anchorNode Express 路径哈希锚点
【发布时间】:2022-08-24 05:23:43
【问题描述】:

我目前在我的 Node 应用程序中有以下 url 结构:

http://localhost:3000/#record_2

单击类似上面的链接会将网页滚动到具有匹配 id 的元素记录_2.

但是我需要可以在我的 Express 路径中检测和使用的额外信息。我尝试了以下方法:

http://localhost:3000/#record_2?test=2
http://localhost:3000/#record_2/test/2

但是,使用以下代码无法识别我的路径:

app.get(\'/#:record/test/:id\', async (request, response) => {
    console.log(\'Request: \', request.params)
    response.redirect(\'/\')
})

app.get(\'/#:record?test=:id\', async (request, response) => {
    console.log(\'Request: \', request.params)
    response.redirect(\'/\')
})

我不需要#记录_???要在服务器上处理的段。我怎样才能得到测试部分返回我的服务器代码进行处理?

    标签: node.js express path anchor


    【解决方案1】:

    路径段和查询选项必须变为哈希符号:http://localhost:3000/?test=2#record_2http://localhost:3000/test/2/#record_2

    【讨论】:

      猜你喜欢
      • 2018-01-21
      • 2011-06-27
      • 2022-01-04
      • 2013-08-22
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      相关资源
      最近更新 更多