Skip to content

Using injectScript inside a NextJs Host #529

Closed Answered by brunos3d
SombreroElGringo asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, @SombreroElGringo. Hope you're doing well bro.

I just made an example reproducing what you're trying to achieve
https://github.com/brunos3d/nextjs-federate-page

Basically the problem is right after when you fetches the container and sets the state using the module loader function without calling it, a problem which I demonstrate here .

In your case to solve it just apply the following changes to your index page in your host app 😄

useEffect(() => {
    injectScript({
      global: 'remote',
      uniqueKey: 'remote',
      url: 'http://localhost:4200/_next/static/chunks/remote.js',
    })
      .then((container) => container.get('./index'))
      .then((data) => {
-        setMicroF…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@SombreroElGringo
Comment options

@khoand3012
Comment options

@brunos3d
Comment options

@khoand3012
Comment options

Answer selected by SombreroElGringo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants