next/router#withRouter TypeScript Examples

The following examples show how to use next/router#withRouter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Item.tsx    From test with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
Item = withRouter(({ router, href, children, icon, onClick, ...props }: ItemProps) => (
  <StyledItem
    {...props}
    href={href}
    active={router && router.pathname === href}
    onClick={
      onClick ||
      (event => {
        event.preventDefault()

        if (router) {
          router.push(href)
        }
      })
    }
  >
    {children}
    {icon && <StyledIcon>{icon}</StyledIcon>}
  </StyledItem>
))
Example #2
Source File: NextLink.tsx    From test with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
NextLink = withRouter(({ router, href, children, ...props }: NextLinkProps) => (
  <Link
    {...props}
    href={href}
    onClick={event => {
      event.preventDefault()

      if (router) {
        router.push(href)
      }
    }}
  >
    {children}
  </Link>
))
Example #3
Source File: NextLink.tsx    From test with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
NextNavLink = withRouter(({ router, href, children, ...props }: NextLinkProps) => (
  <NavLink
    {...props}
    href={href}
    active={router && router.pathname === href}
    onClick={event => {
      event.preventDefault()

      if (router) {
        router.push(href)
      }
    }}
  >
    {children}
  </NavLink>
))
Example #4
Source File: NextLink.tsx    From test with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
NextSidebarLink = withRouter(
  ({ router, href, children, ...props }: NextSidebarLinkProps) => (
    <SidebarLink
      {...props}
      href={href}
      active={router && router.asPath === href}
      onClick={event => {
        event.preventDefault()

        if (router && href) {
          router.push(href)
        }
      }}
    >
      {children}
    </SidebarLink>
  ),
)
Example #5
Source File: index.tsx    From selftrace with MIT License 5 votes vote down vote up
RoutedTabNavigator = withRouter(TabNavigator)