mercredi 1 avril 2015

Express redirect to front-end route with path

Let's say I have a SPA that has a route /contact


For the direct requests to Express (ie. not to index.html) I need to execute a redirect.


In Express I can define this route like this:



app.use(function(req,res,next) {
if (req.path === "/contact" ) {
return res.redirect("/?path=" + req.path);
}
next();
});


This means that if the user makes a direct request they will end up on index.html with "http://ift.tt/1xZhAbP" in their address bar. Then the front-end can take care of the routing etc.


But maybe there is a way to do this so the user does not see this ugly url?


Aucun commentaire:

Enregistrer un commentaire