0

In my nextjs project I have the following case: Let's say I have two templates, myTemplate1 & myTemplate2.

In myTemplate1 after I render my components I have script. E.g:

return (... {renderComponents()} <script src="myscript.js" /> );

This script do something like, displays a virtual toolbox for users.

The case is that if from myTemplate1 page click on a next/link which navigates me to myTemplate2, this virtual toolbox (from script initialization) exists also, I guess because of client routing. Only if I refresh manually the page I get rid of script code after navigating from myTemplate1.

I tried to use appendChild and removeChild at useEffect return but nothing works properly.

Is there any way to avoid this situation, without refreshing the page manually/or from code?

2
  • You want to remove a loaded script when navigating from page1 to page 2?
    – mssp
    Feb 27 at 20:54
  • Yes, this script show a "live chat" lets say in page1, but with next/link navigation to page2 it still exists, and disappears only with refresh
    – Teo
    Feb 28 at 8:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.