Consuming a micro-frontend
Ragu can inject a front-end made by any technology into any application. This article explains how to inject Ragu's micro-frontends into a React application. You must have a React project set up. If you don't have one, we recommend you to start one using create-react-app.
#
Installing the ClientThe ragu-client-react
provides a React component to inject Ragu micro-frontends into any React application.
- Yarn
- NPM
#
Injecting a micro-frontendTo inject a micro-frontend you must provide a manifest
url for one of the available Ragu clients.
Create a simple "Hello, World" micro-frontend that will be injected into our React application.
my-mfe.jsNow start the micro-frontend.
- Yarn
- NPM
This command outputs the follow:
The Component Routes section printed at the terminal describes the
manifest
's routes and that is theURL
we will use to fetch our micro-frontend.Load the micro-frontend using the
manifest
URL usingRaguComponent
.Start the application and see it live!
Does not stop the micro-frontend server
You should keep the micro-frontend running when you start the main application. Otherwise, it will not work.
Code Example
The code of the examples above can be found here.
#
Providing propsIf you want to provide props to a micro-frontend you can just pass it as query parameter
. If you want to provide a
name
parameter to the micro-frontend the RaguComponent
should be called that way:
note
You can read more about providing props at the Core concepts / Consuming a micro-frontend section.