Estoy tratando de construir un pequeño proyecto modular Vanilla SPA JS y estoy usando módulos JS para esto. La estructura de mi proyecto es la siguiente:
/index.html /index.js /js /mypage.js /pages /mypage.htmlmipagina.html
<head> <script src="../js/mypage.js" type="module"></script> </head> <div>whatever content here</div>mipagina.js
console.log('mypage module has loaded')índice.html
<!DOCTYPE html> <html lang="en"> <head> <script src="./index.js" type="module"></script> </head> <body> <div id="app"> </div> </body> </html> index.js carga mypage.html a través de una solicitud de recuperación, luego establece el contenido de la div #app de la siguiente manera:
const content = await fetch(/pages/mypage.html).then(data => data.text()) document.getElementById('app').innerHTML = content