0

The company I work for is currently experimenting with a newer version of their frontend. One piece of functionality is a self-contained React app that feeds off Rails APIs. We'd like to for one part of the app (the React part) use the react router instead of the rails router.

Is there any way for us to be able to embed the react app as its own section of the app whilst still maintaining sessions and being able to use the rails router for the rails components and the react router for the react components.

2 Answers 2

1

Yes this is a very common thing to do especially when migrating into more modern client heavy applications.

Like you said you will use rails to handle session management through cookies and routing will be the tricky part. You may however choose for rails to serve a single page and have react-router handle the rest. That is depending on things like auth see.

Once an html page has been rendered the javascript will load and react-router will handle the rest of the routing. This means that you will not be able to notify rails of client side route changes. It is difficult for me to address if that will be a problem without knowing more about your application design.

Also see this gem.

Sign up to request clarification or add additional context in comments.

Comments

1

// Add react in existing app with yarn

yarn install
yarn add https://github.com/rails/webpacker.git 
yarn add react
yarn add axios 

resolved_paths: ['app/assets'] // Add it in webpacker to get access for assets file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.