Drupal-Decoupled
A list of utilities for a Decoupled integrations
Route Syncronization and comunication between FE and BE via the Iframe
Import the syncDrupalPreviewRoutes
helper at app/root.tsx
import { syncDrupalPreviewRoutes } from "drupal-decoupled";
Make sure your loader returns the current environment
value
export const loader = async ({ context }: LoaderFunctionArgs ) => {
const environment = context.cloudflare.env.ENVIRONMENT
return json(
{
environment,
},
{ status: 200 }
);
};
NOTE: This example is using Cloudflare and taking advantage of Environemt Settings to define "environment" key/value, that is why we are using the context.cloudflare.env.ENVIRONMENT
object to obtain the value and pass it from Server to Client.
Upate your App
function
export default function App() {
const { environment } = useLoaderData<typeof loader>();
const navigation = useNavigation();
if (environment === "preview" && navigation.state === "loading") {
syncDrupalPreviewRoutes(navigation.location.pathname);
}
return (
<>
<Outlet />
</>
);
}
For a fully functional example visit any of those repositories:
Supporting organizations
Development sponsored by Octahedroid