Search code examples
phpreactjsreact-routercontent-management-systemcontao

How to integrate react Router with contao cms


I would like to integrate react router on an application which has been built on top of Contao CMS 3.5.31. We started rendering react components one at a time on various pages/templates but we will soon need to handle navigation between pages. The main problem that I have is that there is no communication between contao's routing system and react's.

I don't know much about contao and the reading I did on the website's docs seems of little use. In summary, if a page request is made to the server and is not found but exists in react router, I would like to make it so that the application redirects to that page.

Any idea how that might be possible ?


Solution

  • Using hash-based routing like (e.g. /users#list) could solve the problem as long as the part before the hash has been setup by creating a page in contao matching that url (/users in this case). Everything after the hash can be handled by React Router. Refer to this documentation for more information about Hash Routing.