How to redirect any page to a single page?
-
If there is a specified key in the session, I want any page to be redirected to the page I specified.
For example, If user visit/recent
/topic
,it will be redirected to/register
(if session is set.)
I tried to use the hookfilter:middleware.render
.If enter the page directly, it works well.But if you change page via ajax(click Home button etc.), it will throw a error : res has been sent.I also tried the hook
filter:router.page
.But I don't know how it works. I search for this hook in Github, But I can't find something useful.Could you give me any help? I don't know how to solve it exactly.I will appreciate it if you help me.
-
Hi @a632079 -- session-sharing uses
filter:router.page
. You could probably take a look and see how it is used there.It is used in a "middleware" style, so it passes in
req
res
andnext
. Just callres.redirect('/route');
if you want to redirect. No need to callnext
unless nothing in your script does anything (and you want NodeBB to continue processing).