Skip to content

Commit

Permalink
Merge pull request #2666 from NDLANO/fix/do-not-pass-rr-props-to-regu…
Browse files Browse the repository at this point in the history
…lar-anchors

fix: do not pass react router props to regular anchors
  • Loading branch information
Jonas-C authored Jan 6, 2025
2 parents 7eff1eb + 4f12749 commit 0554aa0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/safelink/src/SafeLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const StyledLink = styled(Link, {}, { baseComponent: true });
// Fallback to normal link if app is missing RouterContext, link is external or is old ndla link

export const SafeLink = forwardRef<HTMLAnchorElement, SafeLinkProps>(
({ to, replace, disabled, unstyled, children, tabIndex, asAnchor, ...rest }, ref) => {
({ to, replace, state, disabled, unstyled, children, tabIndex, asAnchor, reloadDocument, ...rest }, ref) => {
const isMissingRouterContext = useContext(MissingRouterContext);
const unstyledProps = unstyled ? { "data-unstyled": "" } : {};

Expand All @@ -58,7 +58,16 @@ export const SafeLink = forwardRef<HTMLAnchorElement, SafeLinkProps>(

return (
// RR6 link immediately fails if to is somehow undefined, so we provide an empty fallback to recover.
<StyledLink ref={ref} tabIndex={tabIndex ?? 0} to={to ?? ""} replace={replace} {...unstyledProps} {...rest}>
<StyledLink
ref={ref}
tabIndex={tabIndex ?? 0}
to={to ?? ""}
state={state}
reloadDocument={reloadDocument}
replace={replace}
{...unstyledProps}
{...rest}
>
{children}
</StyledLink>
);
Expand Down

0 comments on commit 0554aa0

Please sign in to comment.