react-router-rails
React Router for Rails asset pipeline
- React Router version: 0.11.6
Installation
- Add to your
Gemfileand install with bundler:
gem 'react-router-rails', '~>0.11.6'
bundle install
- Require the modified React-Router javascript file in
app/assets/javascripts/application.js:
//= require react_router
// OR
//= require react_router.min
Or in app/assets/javascripts/application.js.coffee:
#= require react_router
#OR
#= require react_router.min
#Optional. Gives you the ability to use the view helper in your template
#= require react_router_ujs
- Using the view helper:
Define your routes 'MyRoutes' in any javascript file like you would normally do:
Route = ReactRouter.Route
@AppRoutes = (
<Route handler={App}>
<Route name='home' handler={Home} path='/' />
</Route>
)
In the view helper set the name of your routes component
<%= react_router 'MyRoutes' %>
Optionally set the location handler (defaults to HashLocation):
<%= react_router 'MyRoutes', 'HistoryLocation' %>
- Using React Router in your javascript :
ReactRouter.run(routes, function (Handler) {
React.render(<Handler/>, document.body);
});
Or in coffeescript:
ReactRouter.run(routes, (Handler) ->
React.render <Handler/>, document.body
)
Acknowledgements
This gem is highly inspired and based on React Rails code. Thanks!
React Router by Ryan Florence, Michael Jackson licensed under the MIT license
Copyright Mario Peixoto, released under the MIT license.