module-federation-examples icon indicating copy to clipboard operation
module-federation-examples copied to clipboard

Dynamic route for other MFE's pages

Open umgu opened this issue 2 years ago • 3 comments

The question I have is regarding SSR. I'm trying to implement my application as shown below. https://github.com/module-federation/module-federation-examples/tree/master/nextjs-ssr In these examples, we have imported the pages from other MFEs to create file-based routings. In all MFEs, this has been done. As shown below, I have tried to create a dynamic route for example [...slug].js in the home MFE

const SlugPage = dynamic(() => import("shop/shop"));

const Slug = SlugPage;

Slug.getInitialProps = async (ctx) => { const getInitialProps = (await SlugPage).default?.getInitialProps; if (getInitialProps) { return getInitialProps(ctx); } return {}; };;

export default Slug;

Would it be possible to use such a dynamic route to load other MFEs' pages, for example, when I access '/shop' it should load the index page of the shop, when I access '/checkout' it should load the index page of checkout, and similarly for other MFEs including nested routes like "/shop/products"?

umgu avatar Sep 05 '23 06:09 umgu

Modernjs.dev/en will support this next quarter. Along with SSR support, TS support and HMR

Doing dynamic routes on next is very limited. Only get initial props would work. Modernjs has its router designed for federation.

ScriptedAlchemy avatar Sep 07 '23 01:09 ScriptedAlchemy

Is there any reference related to Modern.js like how to achieve dynamic routing ?

umgu avatar Sep 07 '23 07:09 umgu

In the next release it should be simply built on. "Just works" - there will be a new option like "discoverRoutes: true"

ScriptedAlchemy avatar Sep 13 '23 11:09 ScriptedAlchemy