tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.83k stars 247 forks source link

Missing alert or Logic problem on current route method #748

Closed allanmcarvalho closed 3 months ago

allanmcarvalho commented 3 months ago

Ziggy version

2.1.0

Laravel version

11.5.0

Description

I was having a problem when checking whether a route was the current one. The method was always returning "undefined" when asking for current route or false when comparing with the route name. I looked a lot, I studied Ziggy's src, but nothing made sense. I discovered that this behavior occurs when we configure the same name for the same route. In my case, I mistakenly and unnecessarily put the same name for the patch method for the same URI.

I don't know if it would be worth putting a warning about this in the documentation or treating the code to get around this, but I believe it would be interesting to at least put a warning, as it is not a very clear problem of identifying what is wrong, and an alert would give guidance to the developer.I

Ziggy call and context

// On route 'dashboard.profile.update_data'

// returns undefined
route().current();

// returns false
route().current('dashboard.profile.update_data'
);

Ziggy configuration

// its ok

Route definition

Route::get('/data', [UpdateDataController::class, 'show'])
    ->name('dashboard.profile.update_data');
Route::patch('/data', [UpdateDataController::class, 'update'])
    ->name('dashboard.profile.update_data');