Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

route() in React or Vue throws that a Laravel route is not in Ziggy's list

Your error

Uncaught Error: Ziggy error: route 'posts.index' is not in the route list.1 more line it can show

Fix it fast

Most common cause, 1 of 4

The Laravel route has no name, or a different one

Give the route a unique name in routes/web.php, and call route() with the full name including any group prefix.

Fix
// routes/web.php
Route::get('/posts', [PostController::class, 'index'])->name('posts.index');

// React or Vue component
route('posts.index');
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Ziggy error: route 'x' is not in the route list means the routes Ziggy sent to the browser lack that name. Ziggy only exports named routes, so first add ->name() in Laravel. If php artisan route:list shows the name, regenerate ziggy.js, check the only, except and groups filters, and rebuild the route cache. Applies to Ziggy 2.7 on Laravel 13.

  • Applies to tightenco/ziggy 2.7.0, ziggy-js 2.7.0, Laravel 13.43 on PHP 8.3+
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask Laravel for the route's name, then check what Ziggy sent. A name missing from route:list is cause 1. A name Laravel lists but Ziggy lacks points to causes 2 to 4: with @routes, test it with route().has() in the browser console; with an imported ziggy.js, search that file.

Run this first
php artisan route:list --except-vendor
# pages using @routes, in the browser devtools console:
route().has('posts.index')
# apps importing a generated file:
grep -c "posts.index" resources/js/ziggy.js

Then find the line you see in this list and open its fix:

  1. 1The Laravel route has no name, or a different oneThe route's row in route:list has an empty name, or the name carries a group prefix such as admin.
  2. 2The front end imports a ziggy.js generated before the route existedThe app imports Ziggy from a ziggy.js file instead of using the @routes Blade directive
  3. 3config/ziggy.php or a @routes group filters the route outconfig/ziggy.php has an only, except or groups key, or the layout calls @routes('somegroup')
  4. 4The server still runs on a route cache built before the deployThe page works locally but fails on the server, where the deploy runs php artisan route:cache or php artisan optimize

What does the error look like?

  • Uncaught Error: Ziggy error: route 'posts.index' is not in the route list.
  • Ziggy error: route 'dashboard' is not in the route list.

Cause 1 of 4

The Laravel route has no name, or a different one

You seeThe route's row in route:list has an empty name, or the name carries a group prefix such as admin.

Check

Ziggy's route list is built from Laravel's named routes only, so a route without ->name() can never be found and route() throws the not-in-the-route-list error. A name prefix from Route::name('admin.') is part of the name, so 'users.index' and 'admin.users.index' are different keys.

Check
php artisan route:list --except-vendor | grep posts

Fix

Give the route a unique name in routes/web.php, and call route() with the full name including any group prefix.

Fix
// routes/web.php
Route::get('/posts', [PostController::class, 'index'])->name('posts.index');

// React or Vue component
route('posts.index');

Verify

route:list shows posts.index, and route('posts.index') in the console returns the URL.

Verify
route('posts.index')

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 4

The front end imports a ziggy.js generated before the route existed

You seeThe app imports Ziggy from a ziggy.js file instead of using the @routes Blade directive

Check

php artisan ziggy:generate writes the config and routes to resources/js/ziggy.js (or ziggy.output.path). Without @routes, that file is all route() knows, so a route added after the last generate run is missing from it.

Check
grep -c "posts.index" resources/js/ziggy.js

Fix

Run the generate command again after every route change and rebuild the assets. Adding it to the script that runs your build stops the file going stale.

Fix
php artisan ziggy:generate
npm run build

Verify

The grep now finds the route name in ziggy.js and the page renders without the error.

Verify
grep -c "posts.index" resources/js/ziggy.js

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 4

config/ziggy.php or a @routes group filters the route out

You seeconfig/ziggy.php has an only, except or groups key, or the layout calls @routes('somegroup')

Check

Ziggy applies the only or except patterns from config/ziggy.php to the names it sends, and @routes('author') sends just the routes in that group. A name that no pattern lets through is hidden from route() even though Laravel serves it. Setting both only and except switches filtering off.

Check
cat config/ziggy.php
grep -rn "@routes" resources/views

Fix

Add a pattern that matches the name to only (or to the group the page uses), or take it out of except. If the server caches its config, clear that cache so the edited file is used.

Fix
// config/ziggy.php
return [
    'only' => ['home', 'posts.*'],
];
// then: php artisan config:clear

Verify

route().has('posts.index') returns true on the page that failed.

Verify
route().has('posts.index')

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 4 of 4

The server still runs on a route cache built before the deploy

You seeThe page works locally but fails on the server, where the deploy runs php artisan route:cache or php artisan optimize

Check

Once php artisan route:cache has run (php artisan optimize runs it too), Laravel loads the cached file on every request, and routes added since then stay invisible until the cache is rebuilt. The list that @routes prints comes from that router, so the browser misses the new name as well.

Check
grep -rnE "route:cache|artisan optimize" --include=*.sh --include=*.yml .

Fix

Clear the stale cache, then rebuild it as a step that runs after the new code is on the server, never before.

Fix
php artisan route:clear
php artisan route:cache

Verify

Reload the page on the server; route().has() returns true and the error is gone.

Verify
php artisan route:list --except-vendor | grep posts.index

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Name every route the front end calls, and treat a missing ->name() as a review comment.
  • Run php artisan ziggy:generate inside the same npm script that builds the assets, if you import ziggy.js.
  • In the deploy script, place route:cache after the code checkout and composer install.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater, TaxiDex.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.