SKILL.blade.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ---
  2. name: inertia-svelte-development
  3. description: "Develops Inertia.js v1 Svelte client-side applications. Activates when creating Svelte pages, forms, or navigation; using Link or router; or when user mentions Svelte with Inertia, Svelte pages, Svelte forms, or Svelte navigation."
  4. license: MIT
  5. metadata:
  6. author: laravel
  7. ---
  8. @php
  9. /** @var \Laravel\Boost\Install\GuidelineAssist $assist */
  10. @endphp
  11. # Inertia Svelte Development
  12. ## Documentation
  13. Use `search-docs` for detailed Inertia v1 Svelte patterns and documentation.
  14. ## Basic Usage
  15. ### Page Components Location
  16. Svelte page components should be placed in the `{{ $assist->inertia()->pagesDirectory() }}` directory.
  17. ### Page Component Structure
  18. @boostsnippet("Basic Svelte Page Component", "svelte")
  19. <script>
  20. export let users
  21. </script>
  22. <div>
  23. <h1>Users</h1>
  24. <ul>
  25. {#each users as user (user.id)}
  26. <li>{user.name}</li>
  27. {/each}
  28. </ul>
  29. </div>
  30. @endboostsnippet
  31. ## Client-Side Navigation
  32. ### Basic Link Component
  33. Use `<Link>` for client-side navigation instead of traditional `<a>` tags:
  34. @boostsnippet("Inertia Svelte Navigation", "svelte")
  35. <script>
  36. import { Link } from '@inertiajs/svelte'
  37. </script>
  38. <Link href="/">Home</Link>
  39. <Link href="/users">Users</Link>
  40. <Link href={`/users/${user.id}`}>View User</Link>
  41. @endboostsnippet
  42. ### Link with Method
  43. @boostsnippet("Link with POST Method", "svelte")
  44. <script>
  45. import { Link } from '@inertiajs/svelte'
  46. </script>
  47. <Link href="/logout" method="post">Logout</Link>
  48. @endboostsnippet
  49. ### Programmatic Navigation
  50. @boostsnippet("Router Visit", "svelte")
  51. <script>
  52. import { router } from '@inertiajs/svelte'
  53. function handleClick() {
  54. router.visit('/users')
  55. }
  56. // Or with options
  57. function createUser() {
  58. router.visit('/users', {
  59. method: 'post',
  60. data: { name: 'John' },
  61. onSuccess: () => console.log('Success!'),
  62. })
  63. }
  64. </script>
  65. @endboostsnippet
  66. ## Form Handling
  67. ### Using `router.post`
  68. @boostsnippet("Form with router.post", "svelte")
  69. <script>
  70. import { router } from '@inertiajs/svelte'
  71. let form = {
  72. name: '',
  73. email: '',
  74. }
  75. let processing = false
  76. function handleSubmit() {
  77. processing = true
  78. router.post('/users', form, {
  79. onFinish: () => processing = false,
  80. })
  81. }
  82. </script>
  83. <form on:submit|preventDefault={handleSubmit}>
  84. <input type="text" bind:value={form.name} />
  85. <input type="email" bind:value={form.email} />
  86. <button type="submit" disabled={processing}>
  87. Create User
  88. </button>
  89. </form>
  90. @endboostsnippet
  91. ## Inertia v1 Limitations
  92. Inertia v1 does not support these v2 features:
  93. - `<Form>` component
  94. - Deferred props
  95. - Prefetching
  96. - Polling
  97. - Infinite scrolling with `WhenVisible`
  98. - Merging props
  99. Do not use these features in v1 projects.
  100. ## Server-Side Patterns
  101. Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines.
  102. ## Common Pitfalls
  103. - Using traditional `<a>` links instead of Inertia's `<Link>` component (breaks SPA behavior)
  104. - Trying to use Inertia v2 features (deferred props, `<Form>` component, etc.) in v1 projects
  105. - Using `<form>` without preventing default submission (use `on:submit|preventDefault`)
  106. - Not handling loading states during form submission