Detect internal URLs in menu using config.siteUrl
This is so that menu items defined in Ghost don't get mistakenly processed as external sites
This commit is contained in:
parent
b5851935db
commit
173c5c5654
1 changed files with 4 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Link } from 'gatsby'
|
||||
import config from '../../utils/siteConfig'
|
||||
|
||||
/**
|
||||
* Navigation component
|
||||
|
@ -17,6 +18,8 @@ const Navigation = ({ data, navClass }) => (
|
|||
{data.map((navItem, i) => {
|
||||
if (navItem.url.match(/^\s?http(s?)/gi)) {
|
||||
return <a className={navClass} href={navItem.url} key={i} target="_blank" rel="noopener noreferrer">{navItem.label}</a>
|
||||
} else if (navItem.url.slice(0, config.siteUrl.length) == config.siteUrl) {
|
||||
return <Link className={navClass} to={navItem.url.slice(config.siteUrl.length, navItem.url.length)} key={i}>{navItem.label}</Link>
|
||||
} else{
|
||||
return <Link className={navClass} to={navItem.url} key={i}>{navItem.label}</Link>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue