简体   繁体   English

Express的基本路由问题

[英]Basic Routing Issue with Express

Noobie here using Node/Express. Noobie在这里使用Node / Express。 I've built an app using jQuery Date Range slider, allowing users to select a date range and pull data from a Socrata SODA API. 我使用jQuery日期范围滑块构建了一个应用程序,允许用户选择日期范围并从Socrata SODA API中提取数据。 Working version hosted here. 工作版本托管在此处。

My goal is for user to be able to refresh the page after a query (or Copy/paste/share the URL after a query) and be able to load the same results. 我的目标是使用户能够在查询后刷新页面(或在查询后复制/粘贴/共享URL)并能够加载相同的结果。 I've managed to modify the URL correctly with this: 我设法用以下方法正确修改了URL:

function changeURL(startDate, endDate) { 
  window.history.pushState("ChangeDates", "Title", "/fire/dates?start="+startDate+"%end="+endDate+"");
}

So after running a query the URL is something like: 因此,运行查询后,URL类似于:

[root]/fire/dates?start=2015-01-01%end=2015-02-11

The challenge I'm having is in routing. 我面临的挑战是布线。 Currently a refresh will hit a 404. How to I set up Express to route any url requests with the /fire/[param] to the home page, then pass on the params to trigger the query again? 当前,刷新将达到404。我如何设置Express以将带有/fire/[param]所有url请求路由到主页,然后传递这些参数再次触发查询?

Thanks very much all. 非常感谢。

Why don't you keep the params on the client side using a hash like: 为什么不使用如下哈希将参数保留在客户端:

yourremotadress.org/#start=xxx&end=yyy

You could access the hash variables via: 您可以通过以下方式访问哈希变量:

window.location.hash

So simply read and parse the hash on page load, start the query and show the data? 因此,只需读取并解析页面加载时的哈希值,启动查询并显示数据?

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

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