Skip to content
Darin Larimore
All posts

Moving my Inertia apps from Ziggy to Wayfinder's typed routes

4 min read
On this page
  1. The new way
  2. Mechanics
  3. The production gotcha
  4. Where it pays off
  5. Trade-offs

My older Laravel and Inertia apps used Ziggy. The Blade layout printed @routes, app.ts installed ZiggyVue, and every component called a global route():

<a :href="route('blog.show', post.slug)">
<a :href="route('blog.index', { tag: tag.slug })">

It works until something changes on the PHP side. Rename a route, rename a parameter, swap the parameter order, and nothing fails locally. The JSON dump of the route list is generated at request time, the call is a string, and TypeScript has no idea. You find out as a 404 or a 500 in production, usually from a user. The route list is also baked into the page at request time, so it is one more blob of JSON on every response and one more thing that can be stale if the bundle and the backend deploy at different moments.

Ziggy also leaked into places it had no business being. route().current() decided which nav item was active, so the layout knew about route names.

The new way

Wayfinder generates a TypeScript function per named route and per controller action at build time. In my feedback app the migration converted 244 route() calls across 52 files to typed imports:

import { show, index } from '@/routes/posts';

show(post.slug);                    // { url: '/blog/slug', method: 'get' }
show.url(post.slug);                // '/blog/slug'
index({ query: { tag: 'laravel' } }); // typed query

With formVariants: true in the Vite plugin you also get objects ready for Inertia's <Form :action="store()"> and useForm. Rename the route or change a parameter and vue-tsc fails the build. That is the whole argument. Forms read well too:

<Form :action="store()" v-slot="{ errors, processing }">

The action object carries the URL and the method, so a route that changes from POST to PUT changes the form without anyone touching the template.

I first tried this at the end of 2025 and reverted the PR the same day. The second attempt in September 2026 stuck.

Mechanics

  • The Vite plugin regenerates on route changes in dev. The generated resources/js/routes, actions and wayfinder folders are gitignored.
  • CI has to run the build (or php artisan wayfinder:generate --with-form) before vue-tsc, and the app has to boot, so CI needs an .env before the Vite step.
  • A default export named posts shadows a page prop named posts. Import route objects as postsRoutes and the problem goes away.
  • Components that took href: String need [String, Object] now. Mine threw during SSR because Vue's prop warning is escalated to an exception there, so every dashboard render failed until a one-line prop change.
  • route().current() has no equivalent. I replaced it with a small useCurrentUrl composable that prefix-matches usePage().url, which is what I should have been doing anyway.
  • Ziggy also shared the app URL through its config. Share appUrl as a normal Inertia prop instead and drop the @routes directive from the Blade layout. That change got its own feature test asserting exactly which shared props every page receives, because removing a global is the moment you find out who depended on it.
  • Any button or link component that builds an href should accept a route object as well as a string, so the typed helpers can be passed straight through.

The production gotcha

A stale route:cache from the previous deploy made the plugin skip new routes during npm run build, which produced an empty public/build and 500'd every page. Clear the caches before the frontend build runs, not only after. Locally the same staleness shows up as vue-tsc errors after a pull; php artisan wayfinder:generate --with-form fixes it.

Where it pays off

The biggest win is pairing typed routes with a typed prop contract. This site keeps every page's props in resources/js/types/index.ts, and the controllers have to match. A renamed prop or route now fails type-checking instead of production. Rename a prop and vue-tsc lists every component that reads it. It is the first time the seam between my controllers and my pages has been checked by a tool instead of by me remembering. <Link prefetch :href="show(post.slug)"> works with the objects directly. And there is no global route leaking into every component.

Trade-offs

It is a build step and a pile of generated files. Importing controller actions couples the frontend to PHP class names, so I use named routes for pages and actions only for forms. I would not go back.