Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
rwr-react-router
Advanced tools
Readme
react-router integration plugin for react_webpack_rails.
This integration makes it possible to render previously created router in rails view.
rwr-react_router
to your Gemfile:gem 'rwr-react_router'
$ npm install --save rwr-react-router
react-router
installed.import RWRReactRouter from 'rwr-react-router';
import { integrationsManager } from 'react-webpack-rails';
integrationsManager.register('react-router', RWRReactRouter.integrationWrapper);
RWRReactRouter.register('MyRouter', MyRouter);
<%= react_router('MyRouter') %>
RWRReactRouter.register
accepts both - react-router instance and function.
When registering function instead of react-router instance, integration will take props (if any were passed to react_router
helper) and will pass them to given function as first argument. This way you can pass them down to router of you choice:
function RouterWithProps(props) {
return (
<Router history={browserHistory}>
<Route path="/with_props" component={App} yourName={props}>
<Route path="about" component={About}/>
<Route path="home" component={Home}/>
</Route>
</Router>
);
}
Props passed to route will be available under props.route.yourName
.
To make router work server-side it need to work on browserHistory. Otherwise, rails don't have access to current route in request. This can be achieved by adding wildcard route to rails routes:
get '/server_side/' => 'pages#server_side'
get '/server_side/*path' => 'pages#server_side'
and setting browserHistory for router:
<Router history={browserHistory}>
<Route path="/server_side" component={App}>
...
</Route>
</Router>
note: react router will analyze whole path so don't forget to add rails path part to it.
With valid setup simply enable server side by passing server_side: true
flag in options:
<%= react_router('MyRouter', { foo: :bar }, server_side: true) %>
note: rwr-react_router automatically handles matching, redirects and routing errors. Redirects and 404's are passed to Rails and handled there so you will be redirect or get 404 page like in normal Rails app.
Found a bug in rwr-react_router? Open an issue on GitHub Issues.
Interested in contributing to rwr-react_router? That's great, and thank you for your interest!
After checking out the repo, run bundle exec rake setup:all
to install every environment dependencies.
To get your contributions accepted, make sure:
bundle exec rake test:all
.The gem is available as open source under the terms of the MIT License.
FAQs
rwr-react_router ====
The npm package rwr-react-router receives a total of 1 weekly downloads. As such, rwr-react-router popularity was classified as not popular.
We found that rwr-react-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.