1

I want to have clean URL and my table was working fine untill I update the Livewire now my table is adding query string like ?page=2 from page no2

all code is same like before, after searching I have add this in Livewire controller namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
class ContactsTable extends Component
{
    use WithPagination;
    protected $paginationTheme = 'bootstrap';
    protected $paginationQueryStringEnabled = false;

but its still showing Query String in URL how can I disable this?

Thanks

Mr.SH
  • 397
  • 1
  • 9
  • 27
  • Does this answer your question? [Laravel LiveWire Pagination issue](https://stackoverflow.com/questions/65925996/laravel-livewire-pagination-issue) – codedge Jan 28 '21 at 12:51
  • sorry no , I dont know why protected $paginationQueryStringEnabled = false; is not working – Mr.SH Jan 28 '21 at 13:14
  • 1
    The `$paginationQueryStringEnabled` property is not part of Livewire, you have to custom implement it by extending the trait `WithPagination` and doing your own logic there. – Qirel Jan 28 '21 at 13:26
  • Hello, thanks could you please help me doing this? – Mr.SH Jan 28 '21 at 13:35

1 Answers1

5

In order to prevent the default page query string being appended to the browser you can do the following:

WithPagination.php:

public function getQueryString()
{
    return array_merge(['page' => ['except' => 1]], $this->queryString);
}

As you can see by default it adds page to the queryString property.

To overwrite this behavior you can add the following method to your component:

use Livewire\Component;
use Livewire\WithPagination;

class ContactsTable extends Component
{
    use WithPagination;

    protected $paginationTheme = 'bootstrap';

    public function getQueryString()
    {
        return [];
    }
}

Here we overwrite the getQueryString method that was defined in the WithPagination trait and set it to an empty array.

Remul
  • 7,874
  • 1
  • 13
  • 30