This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <a href="#module1">Module 1</a> | |
| <a href="#module2">Module 2</a> | |
| <script> | |
| window.addEventListener('hashchange', async () => { | |
| const route = window.location.hash.substr(1); | |
| const { myFunction } = await import(`./${route}.mjs`); | |
| myFunction(); | |
| }); | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.addEventListener('hashchange', async () => { | |
| // Extracts the new route | |
| const route = window.location.hash.substr(1); | |
| // Loads the module based on the route | |
| const { myFunction } = await import(`./${route}.mjs`); | |
| myFunction(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (isFeatureEnabled) { | |
| import('./module.mjs').then((module) => { | |
| module.myFunction(); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| button.addEventListener('click', async () => { | |
| const { myFunction } = await import('./module.mjs'); | |
| myFunction(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| button.addEventListener('click', () => | |
| import('./module.mjs').then((module) => { | |
| module.myFunction(); | |
| }) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Static imports | |
| // import { ... } from '...'; | |
| // ... | |
| import('./module.mjs').then((module) => { | |
| // The exports are accessible through the module object | |
| module.myFunction(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const myFunction = () => console.log('This is an exported function!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { myFunction } from './module.mjs'; | |
| myFunction(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import FirstComponent from './FirstComponent.client.js'; | |
| import SecondComponent from './SecondComponent.client.js'; | |
| function MyServerComponent(props) { | |
| const shouldDisplaySecondComponent = ...; // Some logic | |
| return shouldDisplaySecondComponent ? <SecondComponent/> : <FirstComponent/>; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const FirstComponent = React.lazy(() => import('./FirstComponent.client.js')); | |
| const SecondComponent = React.lazy(() => import('./SecondComponent.client.js')); | |
| function MyClientComponent(props) { | |
| const shouldDisplaySecondComponent = ...; // Some logic | |
| return shouldDisplaySecondComponent ? <SecondComponent/> : <FirstComponent/>; | |
| } |