diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index 07c654cd1fc..afca1b64086 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -553,6 +553,12 @@ public function generateUrlParams(array $options = [], $model = null) if (!empty($paging['scope'])) { $scope = $paging['scope']; $currentParams = $this->_config['options']['url']; + + if (isset($url['#'])) { + $currentParams['#'] = $url['#']; + unset($url['#']); + } + // Merge existing query parameters in the scope. if (isset($currentParams['?'][$scope]) && is_array($currentParams['?'][$scope])) { $url += $currentParams['?'][$scope]; diff --git a/tests/TestCase/View/Helper/PaginatorHelperTest.php b/tests/TestCase/View/Helper/PaginatorHelperTest.php index cd3f3f99fa0..237d6f92e9f 100644 --- a/tests/TestCase/View/Helper/PaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/PaginatorHelperTest.php @@ -910,6 +910,10 @@ public function testGenerateUrlMultiplePagination() $result = $this->Paginator->generateUrl(['sort' => 'name']); $expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name'; $this->assertEquals($expected, $result); + + $result = $this->Paginator->generateUrl(['#' => 'foo']); + $expected = '/posts/index?article%5Bpage%5D=3#foo'; + $this->assertEquals($expected, $result); } /**