panr / gatsby-starter-hello-friend

Pretty basic starter for Gatsby that covers all of the essentials. All you have to do is start typing!
MIT License
165 stars 71 forks source link

Main menu doesn't support external links #11

Open oscmedgon opened 4 years ago

oscmedgon commented 4 years ago

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>
      )
    }
  })
}