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 512B

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