in 1 of node files, have function executing every page(simple login implementation). in code below chatbar show specific route. flow page this:
-client logs in...hits '/', , runs below function. showchatbar = false. -immediately page redirects '/chat' route. showchatbar = true. should displaying chat bar now. not.
my thoughts, that...this happens fast showchatbar=true, never gets load. maybe async problem? maybe res.render?
here node.js code
exports.login = function (req, res) { var showchatbar = false, navbutton = '', navtitle='',navsubtitle=''; if(typeof req.url !='undefined'){ if(req.url.indexof('chat')!=-1){ //consumer view showchatbar = true; navbutton = "close"; } if(req.url.indexof('agent')!=-1){ //agent view navbutton = "close"; navtitle='my clients'; } } if(typeof req.headers.referer != 'undefined'){ if(req.headers.referer.indexof('agent')!=-1){ //agent chat view navbutton = "back"; } } res.render('index', {title: 'express', showchatbar: showchatbar, navbutton:navbutton, navtitle:navtitle,navsubtitle:navsubtitle});
};
here ejs portion:
<script> var chatbar =<%= showchatbar %>, navbutton='<%= navbutton %>', navtitle='<%= navtitle %>',navsubtitle='<%= navsubtitle %>'; </script>
thoughts on why not updating template correctly showchatbar = true?
try using req.originalurl
instead of req.url
here's documentation it:
req.url
not native express property, inherited node’s http module.,this property
req.url
; however, retains original request url, allowing rewrite req.url freely internal routing purposes. example, “mounting” feature of app.use() rewritereq.url
strip mount point.
// /search?q=something req.originalurl // => "/search?q=something"
Comments
Post a Comment