Last active
June 23, 2021 09:36
-
-
Save onigoetz/25d38f41192c20223705cf0099476d0b to your computer and use it in GitHub Desktop.
Microfrontends at Swissquote
This file contains 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
define(function() { | |
var platform = require("platform"); | |
var extensions = platform.extensions(); | |
define("my-plugin/router", ["my-plugin/resources/Router.js"], function(Router) { | |
return new Router(); | |
}); | |
// Register the router to the platform, all plugins must return an instance of | |
// interface Router { | |
// route(url: String): void | |
// } | |
extensions.register("ext.router", "my-plugin/router"); | |
}); |
This file contains 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
<script> | |
// Load the platform and all plugins | |
require(["platform", "my-plugin/define"], function(platform) { | |
// Once the platform is loaded, load all routers from plugins | |
const routers = platform.extensions() | |
.loadAll("ext.router") | |
.then(function (routers) { | |
// The routers are ready, update them on the current route | |
routers.forEach(function(router) { | |
router.route(window.location.hash); | |
}); | |
}); | |
}); | |
</script> |
This file contains 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
interface View { | |
show(container: Element): void; | |
hide(): void; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment