Building a website with Ractive on Node.js backend

83 views
Skip to first unread message

Michael Knave

unread,
Sep 12, 2016, 4:16:53 AM9/12/16
to Ractive.js
Hello,

I have simple question.

I am building the website with the ractive on Node backend.

What I want to do is very simple thing. 

I just want to build webpage with several url: e.g. www.something.com/home, www.something.com/aboutus, ....

I have one index.ejs, which is the core structure, then I have several templates for the subpages like about, etc. 

How can I do what when I make a call www.something.com/aboutus ->> it will render the correct aboutus-webpage. 

Please help me. 

Regards
M.

Izzet Pembeci

unread,
Sep 22, 2016, 8:20:32 AM9/22/16
to Ractive.js
Matching urls to pages/templates is called routing. Ractive not being a framework like Angular or Ember trying to solve many problems doesn't come with routing functionality. You are free to choose any routing solution based on your stack. There are standalone JS routing libraries or you can somehow connect Node's Express to Ractive but I haven't done such a thing yet so that's all the advice I can give.

iZzeT

Chris Reeves

unread,
Sep 22, 2016, 2:13:18 PM9/22/16
to Ractive.js
The simplest solution is to simply serve your Ractive app from on any non-service uri. Then whatever handles client-side routing can, I usually use page.js, can pick it up from there. Google can index such SPA-ish sites just fine, and there are hooks for doing analytics and whatnot if you need them from your routing library. Bing doesn't seem to like SPAs yet, and you can't do stuff like AMP with this approach.

If you need correct server-side responses, you can run your SPA on the server and use Ractive's toHTML function to serve the matching HTML injected into your wrapper template. If you're using edge, you can use the enhance flag to tell Ractive to try to use existing DOM that was served with the initial request and (mostly) avoid flashes.

FWIW, I typically go with the SPA approach, where the server only handles serving the app files and fielding service requests.


Thanks, Chris

--
You received this message because you are subscribed to the Google Groups "Ractive.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ractive-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Knave

unread,
Sep 22, 2016, 2:22:34 PM9/22/16
to Ractive.js
Thank you very much for suggestions. 

I have tried to use PageJS. What happens, e.g. after click, it changes url - what is fine. But how can I handle it on NODE ? Because when I press "refresh" on browser, or "back", it shows error or the home page. Can you help me how can I handle this? 

Thanks a lot

Chris Reeves

unread,
Sep 22, 2016, 2:44:05 PM9/22/16
to Michael Knave, Ractive.js
If you serve your page.js-ified app from every uri, all of your page routes should be set up when the page finishes loading. When you call page.start(), it should run the route that matches the current uri, which should update the page with whatever logic is there.


Thanks, Chris

--
Reply all
Reply to author
Forward
0 new messages