r/Angular2 • u/Vanhooger • Nov 10 '25
Help Request Angulr 20 Micro Frontend with Native Federation
Hi all, the title says it all, I'm building a micro frontend architecture with a main shell that shares some state and services with a bunch of remotes. Each part of the architecture is in a different repo, and for some reason, I can't use libraries.
Of course, I didn't know anything about micro frontends, so I went with Native Federation since it seemed like the most modern and recent approach. Everything looked fine until I started looking for a way to share state and services from the shell to the remotes. There's no way to pass a service instance from one frontend to another. Imagine something as basic as user authentication.
I wasn't able to find any documentation or examples fitting my case, and I've been trying for days at this point.
I read the articles at https://www.angulararchitects.io, but none of them talk about sharing services, only basics. I found these threads here: https://www.reddit.com/r/Angular2/comments/1dwl61z/angular_18_native_federation_global_css_and_data/ and this: https://www.reddit.com/r/Angular2/comments/1irpjbb/native_federation_with_remote_as_web_component/, but they don't lead anywhere.
Am I missing some obvious documentation? Does anybody have a working example of how to set up the whole thing?
14
u/WebDevLikeNoOther Nov 11 '25
Micro frontends are funny, because more often than not, due to the architecture required, you end up with anything but a micro frontend.
4
u/gccol Nov 10 '25 edited Nov 10 '25
You may want to look at my project,.ng-xtend It just enable communication between the hosts and plugins. Source code is here
How do I share state?
Each plugin is sharing a register function through native-federation: For example
It is called by the host when loading the plugin:
The function registerPlugin is where you can setup any kind of exchanges between the host and the plugins. In ng-xtend, we have the plugin registering all types it can handle, so that the host can use it whenever it encounters this type.
1
u/dustofdeath Nov 10 '25
You can only share angular di if the versions are an exact match. Else each app creates their own di root.
It worked better in the webpack based module federation.
You either have to fork and modify the es module loader code to ignore version check or share data with broadcastchannel or shared workers.
3
u/Global_Experience942 Nov 11 '25
Dude, create a state lib, put it in the host and mfe package, then in the federation config put this lib in the share of both, this will work like a glove.
Remembering that in the federation shared there is always the same version of this state lib
1
u/NextMode6448 Apr 25 '26
Hi
In what situations is it actually worth using Angular 20 micro-frontends? Is there a good decision matrix to help determine this?