Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Working with Pushstate and NodeJS

Working with Pushstate and NodeJS

Problem

I'm working with NodeJS and HTML5 Pushstate. I have my index.html at "/" with a link to go to "/home/" via pushstate. All it's ok but if I refresh my page on /home/, my server return "Cannot GET /home/".

I just want "/home/" return my index.html file like "/"

My code:

var express = require("express"),
    app = express();

app.use(express.static(__dirname + '/public'));

app.get('/home/', function(req, res, next) {
 //what to do here?
});

app.listen(3001);

Thanks.

Problem courtesy of: Tuizi

Solution

drop the / after/home:

app.get('/home', function(req, res, next) {

Regarding the what to do here, you can gather the data you need, and return the response. Eg: res.end("Hello world!");

If you want the static files to be served at /home, then:

app.use("/home", express.static(__dirname + "/public"));
Solution courtesy of: randunel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Working with Pushstate and NodeJS

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×