index.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>@shaun/alpinejs-router examples</title>
  7. <script src="https://unpkg.com/@shaun/alpinejs-router@1.x.x/dist/es6.min.js" defer></script>
  8. <script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
  9. <script src="https://cdn.tailwindcss.com"></script>
  10. </head>
  11. <body x-data x-init="$router.config({ mode: 'hash' })" class="fixed inset-0 flex flex-col text-gray-900">
  12. <header class="flex-none h-16 px-8 flex flex-row items-center border-b">
  13. <h1 class="text-2xl"><code>@shaun/alpinejs-router</code> examples</h1>
  14. </header>
  15. <div class="flex-1 flex flex-row">
  16. <aside class="flex-none w-72 border-r">
  17. <ul>
  18. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">Home</a></li>
  19. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/hello/someone" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">Hello Someone</a></li>
  20. <li><a x-link.replace.activity="{ exactActive: 'text-blue-600' }" href="/replace-to" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">Replace To</a></li>
  21. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/users/123" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">Regex Params</a></li>
  22. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/users?enabled=true" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">With Query</a></li>
  23. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/js-methods" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">JS Methods</a></li>
  24. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/in-directive" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">In Directive</a></li>
  25. <li><a x-link.activity="{ exactActive: 'text-blue-600' }" href="/not-found" class="px-8 py-4 flex flex-row items-center hover:bg-blue-100">Not Found</a></li>
  26. </ul>
  27. </aside>
  28. <div class="flex-1 flex flex-col">
  29. <div class="flex-1 relative">
  30. <main class="absolute w-full h-full overflow-y-scroll">
  31. <template x-route="" template.preload="/home.html"></template>
  32. <template x-route="/" template.preload="/home.html"></template>
  33. <template x-route="/hello/:name">
  34. <div class="px-16 py-4">
  35. <div>Hello <code x-text="$router.params.name"></code></div>
  36. </div>
  37. </template>
  38. <template x-route="/replace-to">
  39. <div class="px-16 py-4">
  40. <div>Because this page was opened with the <code>`replace`</code> modifier, it will not appear in the <code>`window.history`</code></div>
  41. </div>
  42. </template>
  43. <template x-route="/users/:id(\d+)">
  44. <div class="px-16 py-4">
  45. <div>Profile of the user with id <code x-text="$router.params.id"></code></div>
  46. </div>
  47. </template>
  48. <template x-route="/users" template="/users.html">
  49. <div class="px-16 py-4">
  50. <div>
  51. User profiles that are
  52. <span x-show="$router.query.enabled === 'true'">enabled</span>
  53. <span x-show="$router.query.enabled !== 'true'">disabled</span>
  54. </div>
  55. <div class="pt-16">Current page is `<code x-text="$router.query.page ?? 1"></code>`</div>
  56. <ul class="pt-16 flex flex-row items-center space-x-8">
  57. <li><a x-link :href="$router.resolve({ page: 1 })" class="hover:text-blue-600">Page1</a></li>
  58. <li><a x-link :href="$router.resolve({ page: 2 })" class="hover:text-blue-600">Page2</a></li>
  59. <li><a x-link :href="$router.resolve({ page: 100 })" class="hover:text-blue-600">Page100</a></li>
  60. </ul>
  61. </div>
  62. </template>
  63. <template x-route="/js-methods">
  64. <div x-data="demo()" class="px-16 py-4 flex flex-col space-y-8">
  65. <div>
  66. `<code>$router.push('/hello/world')</code>`
  67. <button @click="goto('/hello/world')" class="hover:text-blue-600">Clicking on me will go to the `<code>/hello/world</code>` page</button>
  68. </div>
  69. <div>
  70. `<code>$router.replace('/hello/world')</code>`
  71. <button @click="replaceTo('/hello/world')" class="hover:text-blue-600">Clicking on me will replace to the `<code>/hello/world</code>` page</button>
  72. </div>
  73. <div>
  74. `<code>$router.resolve({ a: 'b', c: 1 })</code>`:
  75. The resolved URL will be `<code x-text="$router.resolve({ a: 'b', c: 1 })"></code>`
  76. </div>
  77. <div>
  78. `<code>$router.is('/js-methods')</code>`:
  79. <span x-text="$router.is('/js-methods') ? 'yes' : 'no'"></span>,
  80. the current page is `<code>/js-methods</code>`
  81. </div>
  82. <div>
  83. `<code>$router.not('/hello/world')</code>`:
  84. <span x-text="$router.not('/hello/world') ? 'no' : 'yes'"></span>,
  85. the current page is not `<code>/hello/world</code>`
  86. </div>
  87. </div>
  88. </template>
  89. <template x-route="/in-directive">
  90. <div class="px-16 py-4">
  91. <button x-hello="$router" class="hover:text-blue-600">I've passed `<code>$router</code>` to `<code>Alpine.directive</code>`, click me to go to the home page</button>
  92. </div>
  93. </template>
  94. <template x-route.notfound>
  95. <div class="w-full h-full flex justify-center items-center">
  96. <h2 class="text-2xl text-red-600">Error 404 not found</h2>
  97. </div>
  98. </template>
  99. </main>
  100. </div>
  101. <footer class="flex-none border-t">
  102. <div class="px-16 py-4">
  103. <code>$router: <span x-text="JSON.stringify($router)"></span></code>
  104. </div>
  105. <div class="px-16 py-4">
  106. <code>Alpine.$router: <span x-text="JSON.stringify(Alpine.$router)"></span></code>
  107. </div>
  108. </footer>
  109. </div>
  110. </div>
  111. <script src="/app.js"></script>
  112. </body>
  113. </html>