-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NavLocaleLinkコンポーネントをforwardRefでラップし、localeをヘッダーと新しいページボタンに追加 (#486)
- Loading branch information
Showing
6 changed files
with
65 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
import { NavLink, type NavLinkProps, useParams } from "@remix-run/react"; | ||
import { forwardRef } from "react"; | ||
|
||
// NavLinkProps を継承 | ||
// NavLinkProps を継承しつつ、to を上書き | ||
type NavLocaleLinkProps = Omit<NavLinkProps, "to"> & { | ||
to: string; | ||
}; | ||
|
||
export function NavLocaleLink({ | ||
to, | ||
className, | ||
children, | ||
...rest | ||
}: NavLocaleLinkProps) { | ||
const { locale } = useParams(); | ||
export const NavLocaleLink = forwardRef<HTMLAnchorElement, NavLocaleLinkProps>( | ||
function NavLocaleLink({ to, className, children, ...rest }, ref) { | ||
const { locale } = useParams(); | ||
const normalized = to.startsWith("/") ? to.slice(1) : to; | ||
const path = `/${locale}/${normalized}`; | ||
|
||
const normalized = to.startsWith("/") ? to.slice(1) : to; | ||
const path = `/${locale}/${normalized}`; | ||
|
||
return ( | ||
<NavLink to={path} className={className} {...rest}> | ||
{children} | ||
</NavLink> | ||
); | ||
} | ||
return ( | ||
<NavLink ref={ref} to={path} className={className} {...rest}> | ||
{children} | ||
</NavLink> | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters