Instantly share code, notes, and snippets.
mvhoute
/ navigation.js
Created
October 17, 2019 11:31
Navigation component to build the navigation with data from Kentico Kontent
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
import React from 'react'; | |
import { graphql, StaticQuery } from 'gatsby'; | |
import NavigationLink from './navigationLink'; | |
const Navigation = ({ data }) => { | |
const navItems = data.allKenticoCloudItemNavigationRoot.nodes[0].elements.linked_navigation_items; | |
return ( | |
<nav className="navigation"> | |
<ul> |
mvhoute
/ navigationLink.js
Last active
October 17, 2019 11:33
NavigationLink Component to render a navigation item
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
import React from 'react'; | |
import { Link } from 'gatsby'; | |
const NavigationLink = props => { | |
const externalUrl = props.elements.external_url.value; | |
const menuTitle = props.elements.menu_title.value; | |
if (!externalUrl) { | |
const linkedItem = props.elements.linked_item[0].elements.url_slug.value; | |
return <Link activeClassName="active" to={`/${linkedItem}/`}>{menuTitle}</Link>; |