- How does Laravel Wayfinder improve TypeScript development with Laravel?
- Wayfinder auto-generates strongly typed TypeScript functions for your Laravel routes and controller actions. This lets you call backend endpoints directly in your frontend code (e.g., `showPost(1)`) instead of hardcoding URLs or guessing parameters, ensuring type safety and reducing API drift.
- Can I use Wayfinder without Vite or Inertia.js?
- Yes, Wayfinder’s core functionality works without Vite or Inertia.js. The Vite plugin is optional but recommended for automatic regeneration during development. Inertia.js integration is opt-in and enhances form/Link support. The base Artisan command (`wayfinder:generate`) works standalone.
- What Laravel versions does Wayfinder support?
- Wayfinder officially supports Laravel 10+. It’s tested up to Laravel 13, but always check the [changelog](https://github.com/laravel/wayfinder/blob/main/CHANGELOG.md) for version-specific notes. The package is designed to align with Laravel’s routing conventions.
- How do I handle dynamic routes or custom route resolvers?
- Wayfinder relies on Laravel’s standard route naming and model binding. For dynamic routes (e.g., middleware-generated URLs) or custom resolvers, you may need to adjust the generated TypeScript types manually or use the `--skip-actions` flag for problematic controllers. Test thoroughly in staging.
- Should I commit the generated Wayfinder files to Git?
- No, the generated `wayfinder`, `actions`, and `routes` directories can be safely `.gitignored`. They’re fully regenerable on every build or via the Artisan command, ensuring they always match your current Laravel backend.
- Does Wayfinder work with React, Vue, or vanilla TypeScript?
- Absolutely. Wayfinder generates TypeScript definitions that work with any TypeScript-based frontend (React, Vue, Svelte, or vanilla TS). It’s especially useful for Inertia.js apps but isn’t tied to a specific framework. Just import the generated functions into your components.
- How do I customize the output path or skip specific routes/actions?
- Use the `--path` flag to specify a custom output directory (e.g., `--path=resources/js/wayfinder`). To skip generating TypeScript for specific routes or controller actions, use `--skip-routes` or `--skip-actions`. These options are useful for excluding legacy or third-party endpoints.
- What happens if my controller method names conflict with TypeScript reserved words?
- Wayfinder automatically renames controller methods that conflict with TypeScript reserved words (e.g., `delete` becomes `deleteMethod`). You’ll need to update your frontend code to use the renamed function, but this is handled transparently during generation.
- Can Wayfinder generate form attributes like `action` and `method` for traditional HTML forms?
- Yes! Enable form support with the `--with-form` flag during generation. Wayfinder will output TypeScript helpers that dynamically populate `<form>` attributes (e.g., `action`, `method`, `_method`) based on your Laravel routes, simplifying form submissions without hardcoding URLs.
- Are there alternatives to Wayfinder for Laravel + TypeScript routing?
- Alternatives include manually writing TypeScript route constants, using Laravel’s `route()` helper with runtime calls, or packages like `laravel-route-generator`. However, Wayfinder stands out by auto-generating *fully typed* functions for both routes *and* controller actions, reducing manual effort and drift. For headless APIs or non-TypeScript frontends, custom solutions may be more appropriate.