0

Im using pagination.js in order to implement ajax pagination. My code look like this:

function postsPagination(category, count){

      (function(name) {
        var container = $('#pagination-' + name);
        container.pagination({
          dataSource: '{{ route("ajax.posts") }}?category=' + category,
          locator: 'items',
          totalNumber: count,
          pageSize: 40,
          ajax: {
            beforeSend: function() {
              container.prev().html('Loading...');
            }
          },
          callback: function(response, pagination) {
            var dataHtml = '<ul class="col-sm-12 myposts">';

            $.each(response, function (index, item) {
              dataHtml += `<a href="{{ route('frontend.myposts', ['slug' => '']) }}/` +item.slug+ `">
                              <figure class="psot__container" style="background-image: url({{ asset('/uploads/posts/` +item.cover+ `') }})">
                                <figurecaption><p>` +item.name+ `</p></figurecaption>
                              </figure>
                          </a>`;

            });

            dataHtml += '</ul>';

            container.prev().html(dataHtml);
          }
        })
      })('posts');
}

This function is called after loading website and when user check an category. It works correctly but how I can implement routung to this script? When I talk about routinmg I mean about js routing just like in React, Angular, etc. After check category and page I want to change an url without reaload.

  • What do you mean by "_how I can implement routing to this script_"? Can you elaborate your question a bit? Do you want a route inside your `.js` file, or do you want to define a new route, so when the user goes to that route, it executes the script? Or is is something else? – zlatan Aug 21 '19 at 08:05
  • I think this article will help you to achieve routing https://stackoverflow.com/questions/11932869/how-to-dynamically-change-url-without-reloading – Sangita Kendre Aug 21 '19 at 09:06

0 Answers0