Skip to content

Pagination state is lost when navigating back from single post view #385

Closed

Description

@armanist

Description

In the Web Demo module of the Quantum PHP Framework (QF project), pagination state is not preserved when navigating between the post list and a single post view.

Current Behavior

  • Open the paginated list of posts in the web demo module.
  • Navigate to any page other than the first (e.g. page 2 or 3).
  • Click on a post to view its single post page.
  • Use the back arrow (or back navigation provided by the UI) to return to the post list.

Result:

The post list always resets to page 1, and the previously selected pagination page is lost.

Expected Behavior

When returning from a single post view back to the post list, the application should restore the same pagination state (page number and related parameters) that the user was previously on.

Proposed Solution (State-Preserving Back Navigation)

To preserve pagination and search state when navigating between the list and a single post, the list view should pass its current state to the post view in an encoded form.

When rendering links to posts, the list page should:

  • Collect the current list state (e.g. page, search, sort, filters)
  • Serialize it into a small JSON object
  • Encode it using Base64 (URL-safe)
  • Attach it to the post URL as a from parameter

Example conceptually:

/post/{uuid}?from=<base64-encoded-state>

The single post page should then:

  • If from is present, decode it and reconstruct the original list URL for the “Back” button
  • If from is missing (direct visit, bookmark, external link), fall back to the default list URL

Assume the user is on:

/posts?page=3&search=shoose&sort=latest

The list state is represented as JSON:

{
  "page": 3,
  "search": "laravel",
  "sort": "latest"
}

That JSON is then Base64-encoded into something like:

eyJwYWdlIjozLCJzZWFyY2giOiJsYXJhdmVsIiwic29ydCI6ImxhdGVzdCJ9

So the post link becomes:

/post/42?from=eyJwYWdlIjozLCJzZWFyY2giOiJsYXJhdmVsIiwic29ydCI6ImxhdGVzdCJ9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions