fix(Pagination): Allow usage of Pagination component with Next.js #273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ATM when on the first or last page of the pagination component, a
Link
component is generated with nohref
attribute for thefirst / last page
andprevious / next page
elements of the pagination.The issue seem to have been running for almost a year now #170
Issue : Since NextJS can't handle
Link
without anhref
attribute, the whole page crashes if we're on the first or last page of the pagination component.Steps to reproduce : Clone react-dsfr, use a Pagination component in
test/integration/next-appdir/ui/ClientComponent.tsx
.Set
defaultPage
attribue to either 1 or the same ascount
count attribute, andcount
> 1.Run and try to access the page.
example :
Solution :
I tried to solve this in the most simple and straight forward way :
If we're on either the first or last page of the Pagination component, then we use a
<a>
HTML element instead of<Link>
for those specific action links.Since the link is not clickable anyway in such case, this should not cause any issue or regression.