I have a route in express(item/update/), and after that happens I want to send them back to /, I also want to make / show an alert with 'Success' or 'Failure'. I don't want to use query string or hash because I want it to be hidden from the user. I also don't want to render / at items/update as it seems like a bad idea. Also, I have tried the javascript history api, but that seems like a hack as the history api was for something else.
Please let me know if there is any more information you need, Ari
You can do couple of ways,
1.You can redirect to "/" url with query string. Since you don't like to add data in query string, then alternate option is session.
For example,
function itempUpdateHandler(request,response){
//Do some stuff
request.session.displayMsg = "update done successfully";
response.setHeader("Location: http://yourdomain.com/");
response.end();
}
function homepageHandler(request,response){
//Display message here which is read from session.
if(request.session.displayMsg){
console.log(request.session.displayMsg);
delete request.session.displayMsg;
}
//Do your regular suff here.
}
2.You have to take care somewhat more in following method, here you aren't going to redirect but you need modify you handler function as follows,
function itempUpdateHandler(request,response){
//Do some stuff
//response.setHeader("Location: http://yourdomain.com/"); //no need here
homepageHandler(request,response, {display:true, msg: "update done successfully"});
}
function homepageHandler(request,response, moreArgs){
//Display message here which is read from session.
if(moreArgs.display){
console.log(moreArgs.msg);
}
//Do your regular suff here.
}
Note: Assumed you are using express