Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bencarter78@hotmail.com's avatar

Inertia - Ziggy route().current() is undefined

I have installed a fresh laravel 8 project, scaffolded auth with jetstream using Inertia and have then added Ziggy to work with Laravel's routing.

If I console.log(Ziggy.namedRoutes) I can see all of my routes, however if I run route().current() it always return undefined.

// web.php

Route::group(['middleware' => ['auth:sanctum', 'verified']], function () {
    Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
});
// app.js

// As per the Inertia documentation
Vue.prototype.$route = (...args) => route(...args)

// Layout.vue

<template>
	Route: {{ $route().current() }}
</template>

Any ideas what I may be doing wrong?

0 likes
7 replies
bobbybouwmann's avatar

It looks like your implementation is a bit different then what is in the docs

Vue.prototype.$route = (...args) => route(...args).url()

Not sure if current() doesn't work because of the missing .url() or because there is another issue.

1 like
joseph.d's avatar

I experienced the same problem and ultimately noticed that it was only happening when I was developing using Browsersync. The issue was that Ziggy was not providing route().current() when the URL included a port number, even though Ziggy seems to be aware of the port number in it's Router object.

But if I change from http://myapp.local:3000 to http://myapp.local then I can do {{ route().current() }} in a template then even without the $ and without the Vue.prototype.$route... and it works just fine.

I haven't been able to find out how to make it work with URLs which have a port number so if anyone has any idea please let me know!

2 likes
mberneis's avatar

Same problem - I solved it by ignoring the route().current() function and replaced it with the expression (this.route(item.route) == location.pathname)

1 like
aalabiso's avatar

I had the same issue with browsersync and my search brought me here at first. After doing a little digging I found if I commented out APP_URL from my .env file the route().current() function started working again.

Got the idea from this thread: https://github.com/tighten/ziggy/issues/125

2 likes
AcidDiz's avatar

Maybe the package has been updated Docs says it should be used like this...

route()->current('your_route_name', routes_params)

2 likes

Please or to participate in this conversation.