tighten / ziggy

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

Problem with ziggy when route name starts with a number (eg. 404) #657

Closed lukaszahorec closed 1 year ago

lukaszahorec commented 1 year ago

Ziggy version

v1.6.0

Laravel version

v9.52.10

Description

Hello!

There is a problem with ziggy when route name starts with a number eg. 404.

Route::fallback(function () { return response()->view('pages.page-404', ['notfoundPage' => true], 404); })->name('404')->middleware('getlocale');

If it starts with number, then in Vue Component when I try to get routes, it starts with a "0" route. The object containing routes look like this:

image

Then function route().current() on every route return "0".

When I change route name to: Route::fallback(function () { return response()->view('pages.page-404', ['notfoundPage' => true], 404); })->name('error.404')->middleware('getlocale');

Then It's working as expected.

image

Ziggy call and context

Route::fallback(function () {
    return response()->view('pages.page-404', ['notfoundPage' => true], 404);
})->name('404')->middleware('getlocale');

Ziggy configuration

{
    "0": {
        "uri": "{fallbackPlaceholder}",
        "methods": [
            "GET",
            "HEAD"
        ],
        "wheres": {
            "fallbackPlaceholder": ".*"
        }
    }
}

Route definition

Route::fallback(function () {
    return response()->view('pages.page-404', ['notfoundPage' => true], 404);
})->name('error.404')->middleware('getlocale');
bakerkretzmar commented 1 year ago

Thanks, you're right. Looks like this is coming specifically from the collection->merge() method. I'll dig in further on Friday.