AEM integration with React without SPA | Community
Skip to main content
February 1, 2021
Solved

AEM integration with React without SPA

  • February 1, 2021
  • 3 replies
  • 5014 views

I wanted to integrate AEM With React on a non SPA implementation i.e. without SPA editor. Can anyone point to any working documentation

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anudeep_Garnepudi

@tusharwdc 

You can write vanilla React. Set the root path from component/template HTML, hit the path from React and render.

<div id="root" data-root-path="/content/...."></div>

Vanilla React sample

import React from "react"; export default class Test extends React.Component { state = { loading: true }; data = { text: null }; async componentDidMount() { const url = document.getElementById("root").getAttribute("data-root-path")+".model.json"; const response = await fetch(url); const data = await response.json(); this.data = data; this.setState({loading: false}); }; render() { return ( //retuen markup if state.loading is false ); } }

This example is if path is generating from back end. If your path is static, you don't need path in html and skip first line in componentDidMount and fetch url directly.

Hope this helps.

3 replies

Peter_Puzanovs
Community Advisor
Community Advisor
February 1, 2021

Hi Tkantk,

 

The best one I have come so far to achieve your requirement, stunning work by Jenna Salau:

https://github.com/DeloitteDigitalAPAC/react-habitat

 

Regards,

Peter

December 23, 2021

Hi Peter,

 

Is there any other plugin available apart from react-habitat, as this doesnt support functional react components

 

Regards

Ramesh

Peter_Puzanovs
Community Advisor
Community Advisor
December 24, 2021

Hi Ramesh,

 

Check https://www.npmjs.com/package/react-abode as alternative.

 

Regards,

Peter

Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
February 1, 2021

@tusharwdc 

You can write vanilla React. Set the root path from component/template HTML, hit the path from React and render.

<div id="root" data-root-path="/content/...."></div>

Vanilla React sample

import React from "react"; export default class Test extends React.Component { state = { loading: true }; data = { text: null }; async componentDidMount() { const url = document.getElementById("root").getAttribute("data-root-path")+".model.json"; const response = await fetch(url); const data = await response.json(); this.data = data; this.setState({loading: false}); }; render() { return ( //retuen markup if state.loading is false ); } }

This example is if path is generating from back end. If your path is static, you don't need path in html and skip first line in componentDidMount and fetch url directly.

Hope this helps.

Umesh_Thakur
Community Advisor
Community Advisor
February 2, 2021