0.0.1 • Published 10 years ago
ferry v0.0.1
Ferry
Simple express middleware for server-side routing with React.
npm install ferryUsage
##1. Call ferry.route with your configuration in the express app.use function to use ferry as middleware.
var Main = React.createFactory(require('./app/components/Main'));
var ferry = require('./ferry.js');
var app = express();
app.use(ferry.route({ /* config options */ }));ferry.route options
ferry.route accepts an options object, with 3 required parameters:
parentComponentFactoryis a React factory.htmlPathis the file path of the layout HTML file.routesis a JSON array of route objects consisting of apathandcomponentFactory.
app.use(ferry.route({
parentComponentFactory: Main,
htmlPath: __dirname + '/public/layout.html',
routes: [
{
path: '/',
componentFactory: Home
},
{
path: '/work',
componentFactory: Work
},
{
path: '/contact',
componentFactory: Contact
}
]
}));##2. Put "ferryTemplate" (without quotes) in the your HTML file. Ferry replaces this string with the HTML generated by your react component factory.
<!-- ... -->
<body>
<div style="width:100%;height:100%;">
ferryTemplate
</div>
</body>
<!-- ... -->Running tests
npm test
License
MIT. Copyright (c) Sterling Whitley
0.0.1
10 years ago