Documentation on making ajaxify.go work for custom routes?
-
Also, for anyone else researching how to create properly ajaxify'ed custom routes, I came across the old discussion linked below started by @riteshsanap where it appears he figured out how to do this correctly, but his gist has been covered by the sands of time, and I'm not sure I understand his last comment out of context. Anyway, somebody out there has made this work properly https://community.nodebb.org/topic/3857/custom-routes-are-not-ajaxified
-
@jongarrison you really ought to look at some plugins for examples on how to add custom routes. It involves a template file and an express listener.
If you are just adding custom static pages, you may want to use the static pages plugin for that.
-
@pitaj I can do simple pages using express routes no problem. The trick is when there is a link to the custom pages that gets intercepted by ajaxify's go stuff. At that point, ajaxify starts to look for a template and an api route that it can render client side, right?
The suggestion to dig through the existing plugins is great and I've been doing lots of that. I'm sure I'll find something. Thanks!
-
@jongarrison Yes, pretty much all plugins do this. You'll notice for the admin page, we load up two routes:
nodebb-plugin-quickstart/library.js at master 路 NodeBB/nodebb-plugin-quickstart
A starter kit for quickly creating NodeBB plugins. - nodebb-plugin-quickstart/library.js at master 路 NodeBB/nodebb-plugin-quickstart
GitHub (github.com)
Check out the controllers, and mimic in your plugin appropriately
-
@julian Thanks for that example! I had somehow missed this with the custom pages I had done earlier because of how they were being used. Anyway, good to see a concrete example. I really like the way that the page loads work in NodeBB and that server side rendering is similar to client side rendering. it's really slick.
-
@julian Thanks for the link to nodebb-plugin-quickstart, the really important bit for me was the comment in nodebb-plugin-quickstart/lib/controllers.js:
/* Make sure the route matches your path to template exactly. If your route was: myforum.com/some/complex/route/ your template should be: templates/some/complex/route.tpl and you would render it like so: res.render('some/complex/route'); */
I hadn't seen that mentioned anywhere else. So, if I understand custom routes finally, there are really three important routes really:
- The normal Express route which renders the full page with the header. This handles browser requests straight to the custom route.
- API route for Ajaxify. The custom plugin code sends some json, which nodebb adds some additional json to.
- Template route for Ajaxify, which is implied from the url for the api path.
-
Sweet!