@faizanzahid Honestly, we've never tried it. If you enable it, let us know what happens 😬
How to redirect any page to a single page?
a632079 last edited by a632079
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
/topic,it will be redirected to
/register(if session is set.)
I tried to use the hook
filter: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.
It is used in a "middleware" style, so it passes in
next. Just call
res.redirect('/route');if you want to redirect. No need to call
nextunless nothing in your script does anything (and you want NodeBB to continue processing).
@julian I am troubled by this problem for many days. Now I can continue to develop. Thank you very much
@julian First, Thank you very much. but after testing, I found it's still unable to let ajax request to redirect.
To solve it, should I use
filter:middle.renderto add a script to redirect?
@a632079 Ah, that is a more specific workflow, if you need to handle both cold loads and API, you'll need to do something like this:
Instead of calling
@julian Ahhh, It's great! Thanks.
No problem. I forget it all the time too