Skip to content

Commit

Permalink
Handle URLs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Nov 2, 2024
1 parent cbef248 commit 829fdff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Http/Livewire/LivewireCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ class LivewireCollection extends Component
#[Locked]
public $allowedFilters;

#[Locked]
public $currentPath;

public $paginate;

public $view = 'livewire-collection';

public function mount($params)
{
$this->currentPath = request()->path();
$this->allowedFilters = false;
if (is_null($this->params)) {
$this->setParameters($params);
Expand Down
6 changes: 5 additions & 1 deletion src/Http/Livewire/Traits/HandleParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ protected function updateCustomQueryStringUrl(): void
? ''
: $prefix.'/'.$segments->implode('/');

$this->dispatch('update-url', newUrl: url($path));
$fullPath = $path
? trim($this->currentPath, '/').'/'.trim($path, '/')
: $this->currentPath;

$this->dispatch('update-url', newUrl: url($fullPath));
}

protected function dispatchParamsUpdated(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/CustomQueryStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ public function it_dispatched_the_update_url_event_with_the_correct_url()
modifier: 'any',
)
->assertDispatched('update-url')
->assertDispatched('update-url', fn ($name, $payload) => $payload['newUrl'] === 'http://localhost/filters/title/I Love Guitars/item_options/option1');
->assertDispatched('update-url', fn ($name, $payload) => str_contains($payload['newUrl'], 'filters/title/I Love Guitars/item_options/option1'));
}
}

0 comments on commit 829fdff

Please sign in to comment.