Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query param pageTrigger breaks link for first page #4550

Closed
lukasgeiter opened this issue Jul 12, 2019 · 1 comment
Closed

Query param pageTrigger breaks link for first page #4550

lukasgeiter opened this issue Jul 12, 2019 · 1 comment

Comments

@lukasgeiter
Copy link

Description

Using a pageTrigger with a query param format (e.g. ?page) breaks the link for the first page when the user is on any other page. Instead of having no page parameter, the link points to the current page.

Steps to reproduce

  1. Set the pageTrigger config to ?page
  2. Implement pagination. Example:
    {% paginate craft.entries.limit(1) as pageInfo, entries %}
    {# display entries... #}
    {% for page, url in pageInfo.getRangeUrls(1, pageInfo.totalPages) %}
        <a href="{{ url }}">{{ page }}</a>
    {% endfor %}
  3. Use the pagination to jump to page 2 (or any other page except 1)
  4. Now the URL for the first page in the pagination will be ?page=2 instead of having no query parameter for the page.

Further analysis

I think I've found the reason for this bug in getPageUrl method in Paginate.
If it's the first page the code doesn't add the query param to the url while preserving any existing params. Both behaviors on their own are fine, however if the page query param exists, it is kept and results in the wrong URL.

Additional info

  • Craft version: 3.2.1
  • PHP version: 7.2.19
@brandonkelly
Copy link
Member

Thanks for reporting that! Just fixed for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#e516dcb2eac535c88fea172dc148ba1084f9b0eb as 3.2.1",
  "...": "..."
}

Then run composer update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants