tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.91k stars 248 forks source link

Incorrect anchor handling #551

Closed daniser closed 1 year ago

daniser commented 2 years ago

Ziggy version

v1.4.6

Laravel version

v9.8.1

Description

Laravel's URL generator have separate algorithm for handling URL fragments (anchors?): \Illuminate\Routing\RouteUrlGenerator::addQueryString. Fragments are always appended to the end of query string and have no '=' after them.

Ziggy lacks that handy feature. That's the difference between Laravel and Ziggy generated URLs for the same route:

Laravel/Blade:

route('order', [123, '#details', 'param' => 'test']);

=>https://domain.com/orders/123?param=test&#details

Ziggy:

route('order', [123, '#details', {param: 'test'}]);

=>https://domain.com/orders/123?#details=&param=test

Ziggy call and context

route('order', [123, '#details', {param: 'test'}]);

Ziggy configuration

{
    "url": "https://domain.com",
    "port": null,
    "defaults": {},
    "routes": {
        "order": {
            "uri": "orders/{order}",
            "methods": [
                "GET",
                "HEAD"
            ],
            "wheres": {
                "order": "\\d+"
            }
        }
    }
}

Route definition

Route::get('/orders/{order}', [OrderController::class, 'index'])->where('order', '\d+')->name('order');