-
Notifications
You must be signed in to change notification settings - Fork 759
Using react router
Seoung Ho Jeong edited this page Apr 14, 2017
·
4 revisions
solution of origamih from this issue
- Download the React-router library https://cdnjs.cloudflare.com/ajax/libs/react-router/3.0.5/ReactRouter.min.js
Put it in vendor/assets/javascripts, require it in application.js
Or you can put it in app/assets/javascript (no need to require) - Define the essential React-router variables some where in those javascript asset files.
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Link = ReactRouter.Link;
var IndexRoute = ReactRouter.IndexRoute;
var IndexLink = ReactRouter.IndexLink;
var IndexRedirect = ReactRouter.IndexRedirect;
var hashHistory = ReactRouter.hashHistory;
var browserHistory = ReactRouter.browserHistory;
- Add the react_component helper into your view, says the component is ReactHome, this will render the Router component
<%= react_component 'ReactHome' %>
- Add the jsx code for Router, in this code you can add the actual React component
var ReactHome = React.createClass({
render() {
return (
<Router history={hashHistory}>
<Route path="/" component={your_react_component}>
</Route>
</Router>
);
}
});