AEM integration with React without SPA

Avatar

Avatar

tkantk

Avatar

tkantk

tkantk

01-02-2021

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

aem6.5 non-spa React JS

Accepted Solutions (0)

Answers (3)

Answers (3)

Avatar

Avatar

Anudeep_Garnepudi

MVP

Avatar

Anudeep_Garnepudi

MVP

Anudeep_Garnepudi
MVP

01-02-2021

@tkantk 

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.

Avatar

Avatar

Umesh_Thakur

MVP

Avatar

Umesh_Thakur

MVP

Umesh_Thakur
MVP

01-02-2021

Hope this community article will help  for your requirement. 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/use-reactjs-components-in-...

 

Umesh Thakur

Avatar

Avatar

PuzanovsP

MVP

Avatar

PuzanovsP

MVP

PuzanovsP
MVP

01-02-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