I want to add AMP pages for nodebb pages,is there is any plugin for that?
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). -
@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
res.render('template')
or usefilter:middle.render
to 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:
helpers.redirect(res, '/login');
Instead of calling
res.redirect
by itself. -
@julian Ahhh, It's great! Thanks.
-
No problem. I forget it all the time too