mystor / meteor-routecore

Client and server side rendering/routing powered by React
84 stars 6 forks source link

Not rendering server side #11

Closed marpett closed 9 years ago

marpett commented 9 years ago

Hey, great work on RouteCore, it was exactly what I was looking for. The routing is working well, but I'm having some problems getting react rendering to work server side. I'm fairly new to Meteor so this might not be an issue with RouteCore, but I'm not sure where else to ask. Basically, the initial source looks like this:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
  __fast_render_config = {"subscriptions":{},"serverRoutePath":"/sv/","subscriptionIdMap":{},"loadedSubscriptions":{}}
</script>

  <link rel="stylesheet" type="text/css" class="__meteor-css__" href="/ff3f5021068dc3ed03f09c93cbf109ced1be914f.css">

<script type="text/javascript">__meteor_runtime_config__ = {"meteorRelease":"METEOR@0.9.1.1","ROOT_URL":"http://localhost:3000/","ROOT_URL_PATH_PREFIX":"","autoupdateVersion":"31d59e6f3166c778b0f2f84a51804c14ddd0a998","autoupdateVersionRefreshable":"8b2b0c043a0ac0a98c537170b9cf92851760c6c8"};</script>

  <script type="text/javascript" src="/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18"></script>
  ... more scripts

<title>...</title>
  <script src="http://www.youtube.com/player_api"></script>
<script type="text/javascript">
  if(typeof Package['meteorhacks:fast-render'].__init_fast_render == 'function') {
    Package['meteorhacks:fast-render'].__init_fast_render("%7B%22collectionData%22:%7B%7D%7D")
  }
</script>
</head>
<body>

</body>
</html>

collectionData seems to be empty, and nothing is rendered in body on initial load. Any idea what I've done wrong?

mystor commented 9 years ago

It looks to me like your code isn't running on the server side. Where have you put your routecore rendering code? For routecore to cause rendering to also occur on the server, you cannot put any of your code in the client/ folder. Code in the client folder isn't run on the server, and thus server-side rendering won't occur.

marpett commented 9 years ago

Thank you, that was part of the problem. The other part was that I wasn't familiar enough with fast-render to know to put this.subscribe in the routes, i.e:

RouteCore.map(function() {
  Routes.page = this.route('/:someparameter', function(ctx) {
    this.subscribe("collection", ctx.params.someparameter);
    return Page(ctx);
  });
});