datarecall's avatar

Livewire Pagination

When creating a custom pagination view, do you have any idea how I can add withQueryString() and page increment/decrement so bots can crawl it (google etc)

this is what I am using for my custom pagination view currently:

@if ($paginator->hasPages())
{{--    {{dd($paginator->nextPageUrl())}}--}}
    @if($paginator->hasMorePages())
        <div class="load-new-reply has-text-centered mt-15 mb-30">
            {{dump($paginator->nextPageUrl())}}
            <a wire:click.prevent="nextPage" href="{{ route('forum.index', ['page' => $paginator->currentPage() + 1]) }}" rel="next"
               class="has-text-weight-bold">{{ $message }}</a>
        </div>
    @endif
@endif

While this works it doesn't allow for queryString so changing it to :

@if ($paginator->hasPages())
{{--    {{dd($paginator->nextPageUrl())}}--}}
    @if($paginator->hasMorePages())
        <div class="load-new-reply has-text-centered mt-15 mb-30">
            {{dump($paginator->nextPageUrl())}}
            <a wire:click.prevent="nextPage" href="{{ $paginator->nextPageUrl() }}" rel="next"
               class="has-text-weight-bold">{{ $message }}</a>
        </div>
    @endif
@endif

Produces this URL in the href :

/livewire/message/forum-home?page=5

Which is uncrawlable, is there any way you can think of to provide the query string and get livewire to have the proper href's in the pagination links?

0 likes
7 replies
Snapey's avatar

Why would the bots not just crawl the pagination links?

datarecall's avatar

@snapey its giving the wrong href link when using livewire pagination, unless I'm missing something. From what I can tell the pagination relies on the nextPage method, so there is no way for a bot to realize that appending page 2 to the query string will give u page 2 results.

When using nextPageUrl it gives you this as the link

/livewire/message/forum-home?page=5

Snapey's avatar

ok, yes, I can see that would be an issue. Perhaps ask on the Livewire Forum incase anyone there has any ideas, otherwise (and perhaps in addition) make sure you have an xml sitemap to all your content?

Snapey's avatar

how about a normal href to the named route for the next page, and make sure your pages are loadable without javascript?

datarecall's avatar

Thats what I was thinking, need to find a way to append the request parameters to the URL somehow though, any thoughts on how I would do that @snapey ?

Snapey's avatar

Normal Livewire pagination updates the query string ?

What I was thinking was a wire:click.prevent on a standard next page anchor then if no javascript then it does a regular next page load, but normally loads next page through livewire.

1000ml's avatar

@Snapey same problem here. I was trying to setup the wire:click.prevent . hope this will work

Please or to participate in this conversation.