Yichi  Xing Yichi Xing - 1 year ago 105
React JSX Question

How to use react build websites without using react-router ?

I'm building a website with Django and react, and since Django itself has a routing system, and I don't want to discard that, so I decide not to use javascript routing libraries.

I'm using webpack to bundle my files, but since I'm not using react router, there's a lot of webpack entry files, and a lot of bundled files (almost one per page), and I'm not sure if this is a 'correct' way.

And since there's one javascript file per page, the states or other things between different pages are not shared, every page is independent of each other. Can I have some 'shared' things without using react-router?

I know Facebook itself and Airbnb don't use react-router either, so how do they use react? How do they handle a lot of bundled files?

Can anyone work for a company that does not use react-router share your company's solutions?

Answer Source

The proper way to accomplish this is in the same way as you do it using vanilla javascript or some library like jQuery.

You don't manage a state in the front end, you grab the state server side and you put it in the HTML and then you use it with javascript.

React.js isn't different and if you're using redux you could put that data directly in the initial state of every page/section of your whole webpage.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download