Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Main menu doesn't support external links #11

Open
oscmedgon opened this issue Jul 11, 2019 · 0 comments
Open

Main menu doesn't support external links #11

oscmedgon opened this issue Jul 11, 2019 · 0 comments

Comments

@oscmedgon
Copy link

I did a small change to support it in my case, but I want to understand why is not supported

const MainMenu = ({ mainMenu, mainMenuItems, isMobileMenu }) => {
  const menu = mainMenu.slice(0)
  !isMobileMenu && menu.splice(mainMenuItems)

  return menu.map((menuItem, index) => {
    const urlRegex = /^(https?:\/\/)?([\da-z\.-]+\.[a-z\.]{2,6}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?$/im
    const isAbsoluteUrl = menuItem.path.match(urlRegex);
    if (isAbsoluteUrl) {
      return (
        <li key={index}>
          <a href={menuItem.path} target='_top'>{menuItem.title}</a>
        </li>
      )
    } else {
      return (
        <li key={index}>
          <Link to={menuItem.path}>{menuItem.title}</Link>
        </li>
      )
    }
  })
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant