简体   繁体   中英

Basic Routing Issue with Express

Noobie here using 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. 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. I've managed to modify the URL correctly with this:

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:

[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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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