You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Router.svelte 576B

123456789101112131415161718192021222324252627282930313233
  1. <main>
  2. <svelte:component this={element} />
  3. </main>
  4. <script>
  5. import MainMenu from "./MainMenu.svelte";
  6. import SceneSelector from "./SceneSelector.svelte";
  7. import Sandbox from "./Sandbox.svelte";
  8. let routes = {
  9. "/": MainMenu,
  10. "/play": SceneSelector,
  11. "/sandbox": Sandbox,
  12. };
  13. let element = null;
  14. function route() {
  15. let path = location.hash.substr(1);
  16. if (path == "") {
  17. path = "/";
  18. }
  19. if (routes[path] != null) {
  20. element = routes[path];
  21. } else {
  22. element = routes["/"];
  23. }
  24. }
  25. route();
  26. window.addEventListener("hashchange", route);
  27. </script>