-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #627 from lightsound/develop
pathpidaの導入
- Loading branch information
Showing
12 changed files
with
63 additions
and
28 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,4 +1,5 @@ | ||
**/node_modules/* | ||
**/out/* | ||
**/.next/* | ||
/.eslintrc.js | ||
/.eslintrc.js | ||
**/$path.ts |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ __tests__ | |
node_modules | ||
yarn.lock | ||
package-lock.json | ||
public | ||
public | ||
**/$path.ts |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import type { LinkProps } from "next/link"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import type { ReactElement } from "react"; | ||
import type { FC, ReactElement } from "react"; | ||
import { cloneElement } from "react"; | ||
|
||
type Props = LinkProps & { children: ReactElement; activeClassName: string }; | ||
|
||
/** | ||
* @package | ||
*/ | ||
export const NavLink = (props: Props) => { | ||
// eslint-disable-next-line react/destructuring-assignment | ||
const { activeClassName, children, ...linkProps } = props; | ||
export const NavLink: FC<Props> = ({ | ||
activeClassName, | ||
children, | ||
...linkProps | ||
}) => { | ||
const router = useRouter(); | ||
const pathname = router.pathname === "/root" ? "/" : router.pathname; | ||
|
||
const className = | ||
pathname === linkProps.href | ||
? `${activeClassName} ${children.props.className ?? ""}` | ||
: children.props.className ?? ""; | ||
|
||
return <Link {...linkProps}>{cloneElement(children, { className })}</Link>; | ||
return ( | ||
<Link {...linkProps}> | ||
{cloneElement(children, { | ||
className: | ||
router.pathname === linkProps.href | ||
? `${activeClassName} ${children.props.className ?? ""}` | ||
: children.props.className ?? "", | ||
})} | ||
</Link> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const pagesPath = { | ||
"about": { | ||
$url: (url?: { hash?: string }) => ({ pathname: '/about' as const, hash: url?.hash }) | ||
}, | ||
$url: (url?: { hash?: string }) => ({ pathname: '/' as const, hash: url?.hash }) | ||
} | ||
|
||
export type PagesPath = typeof pagesPath | ||
|
||
export const staticPath = { | ||
favicon_ico: '/favicon.ico' | ||
} as const | ||
|
||
export type StaticPath = typeof staticPath |
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,5 +1,5 @@ | ||
import type { VFC } from "react"; | ||
import type { FC } from "react"; | ||
|
||
export const About: VFC = () => { | ||
export const About: FC = () => { | ||
return <h2>About!</h2>; | ||
}; |
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