In this episode, we take a look at how to improve our routing in a Laravel + Inertia + Vue setup using Ziggy. At the start, we've been referencing our routes by their actual URLs in the frontend, which can become a mess if those URLs ever change. Instead, the better way is to use named routes, and reference everything by those—so if a URL changes, your code isn't full of broken links.
We introduce Ziggy, a package that lets you access your Laravel named routes right from JavaScript. First, we pull in the package with Composer, then see how Ziggy grabs all our route info. We explore how to dump and share this data from the backend to our JavaScript components, making it easily accessible across our app. We walk through the setup—installing Ziggy JS on the frontend, configuring Vite with an alias for smoother imports, and globally exposing the named routes.
You'll see how to connect the Ziggy-generated routes to your Vue components and swap out hardcoded URLs for the global route function—making your links much more maintainable. Plus, we check that this keeps working nicely even if we rename or restructure our URLs—no more hunting down old links! This is all about making your app's routing more robust and developer-friendly.