Skip to content

yourcelf/meteor-react-router-ssr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Install

meteor add reactrouter:react-router-ssr

Usage

ReactRouterSSR.Run(routes, [clientOptions], [serverOptions])

The routes argument takes the routes you want react-router to use (you don't have to call React.render() yourself)
Read the react-router documentation for more informations.

routes

Your main <Route /> node of your application.

clientOptions (optional)

The additional arguments you would like to give to the <Router /> component on the client.

serverOptions (optional)

The additional arguments you would like to give to the <Router /> component on the server.

Server-side cookies

Also brings ReactCookie to work with cookie both server-side and client-side. Cookies modified on the server are sent to the client. You can use ReactCookie.save and ReactCookie.load.
See the react-cookie readme for more informations.

Example

const {Route} = ReactRouter;

AppRoutes = (
  <Route path="/" component={App}>
    <Route path="/" component={HomePage} />
    <Route path="login" component={LoginPage} />
    <Route path="*" component={NotFoundPage} />
    {/* ... */}
  </Route>
);

ReactRouterSSR.Run(AppRoutes, {
  onUpdate() {
    // Notify the page has been changed to Google Analytics
    ga('send', 'pageview');
  }
});

if (Meteor.isClient) {
  // Load Google Analytics
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-X', 'auto');
  ga('send', 'pageview');
}

Warning

This is using react-router 1.0 even though it is still in beta. The API is stable and working very well in production.

About

Server-side rendering for react-router and react-meteor-data rehydratating Meteor subscriptions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published