Skip to content

Instantly share code, notes, and snippets.

@onigoetz
Last active June 23, 2021 09:36
Show Gist options
  • Save onigoetz/25d38f41192c20223705cf0099476d0b to your computer and use it in GitHub Desktop.
Save onigoetz/25d38f41192c20223705cf0099476d0b to your computer and use it in GitHub Desktop.
Microfrontends at Swissquote
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");
});
<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>
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